#C14110. Building Hops
Building Hops
Building Hops
You are given a sequence of buildings with heights \(h_1, h_2, \ldots, h_n\). Starting from the first building, you want to determine whether you can reach the last building by performing consecutive jumps. A jump from building \(i\) to building \(i+1\) is allowed if and only if
\(h_{i+1} \le h_i + k\)
where \(k\) is a given non-negative integer representing the maximum allowable increase in height for a jump. If the sequence of jumps from the first to the last building is feasible, output True
; otherwise, output False
.
Note: If there are no buildings, it is impossible to reach the last building.
inputFormat
The input is given via standard input (stdin) in the following format:
- An integer \(n\) representing the number of buildings.
- If \(n > 0\), a line of \(n\) space-separated integers denoting the heights of the buildings.
- An integer \(k\), the maximum allowed height difference for a single jump.
If \(n = 0\), the line of building heights may be omitted.
outputFormat
Output a single line to standard output (stdout) containing either True
or False
, indicating whether it is possible to reach the last building from the first one.
5
1 2 3 4 5
2
True