#K7696. Hiking Trail Validation

    ID: 34758 Type: Default 1000ms 256MiB

Hiking Trail Validation

Hiking Trail Validation

You are given a sequence of hill elevations and an integer d. Your task is to determine whether it is possible to hike the trail such that every downhill segment (i.e. when moving from hill hi-1 to hi with hi-1 > hi) does not exceed the maximum allowed drop d. In mathematical terms, for every index i from 2 to n, if hi-1 > hi, then it must be that:

\( h_{i-1} - h_i \leq d \)

If this condition holds for all consecutive hills, then the hike is valid. Otherwise, it is not.

inputFormat

The input is read from standard input (stdin) and consists of three lines:

  1. The first line contains an integer n representing the number of hills.
  2. The second line contains n space-separated integers representing the elevations of the hills.
  3. The third line contains an integer d, the maximum allowed drop between consecutive hills.

outputFormat

Print True if the trail is valid according to the condition, otherwise print False. The output should be written to standard output (stdout).

## sample
5
10 20 15 25 10
10
False