#K78662. Taco Jump

    ID: 35137 Type: Default 1000ms 256MiB

Taco Jump

Taco Jump

The Taco Jump problem challenges you to determine whether it is possible to travel from the first building to the last building under specific constraints. You are given a sequence of buildings with varying heights and an integer jumpHeight that dictates both the maximum index distance you can jump and the maximum allowed difference in height between two buildings.

A jump from building i to building j is allowed if and only if

\( |i - j| \leq jumpHeight \) and \( |h[i] - h[j]| \leq jumpHeight \),

where \( h[k] \) denotes the height of the \( k^{th} \) building. Your task is to determine if such jumps allow you to reach from the first building to the last one.

Input and Output via Standard I/O: This problem reads input from stdin and produces output to stdout.

inputFormat

The input consists of two lines:

  • The first line contains two integers n and jumpHeight, where n is the number of buildings.
  • The second line contains n space-separated integers representing the heights of the buildings.

\(1 \leq n \leq 10^5\), and building heights and jumpHeight are positive integers.

outputFormat

Output a single line containing YES if it is possible to travel from the first to the last building under the given constraints; otherwise, output NO.

## sample
5 3
4 2 7 6 9
YES

</p>