#AT1399. C - Build Stairs

C - Build Stairs

C - Build Stairs

Score : $300$ points

Problem Statement

There are $N$ squares arranged in a row from left to right. The height of the $i$-th square from the left is $H_i$.

For each square, you will perform either of the following operations once:

  • Decrease the height of the square by $1$.
  • Do nothing.

Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.

Constraints

  • All values in input are integers.
  • $1 \leq N \leq 10^5$
  • $1 \leq H_i \leq 10^9$

Input

Input is given from Standard Input in the following format:

NN

H1H_1 H2H_2 ...... HNH_N

Output

If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print Yes; otherwise, print No.


5
1 2 1 1 3
Yes

You can achieve the objective by decreasing the height of only the second square from the left by $1$.


4
1 3 2 1
No

5
1 2 3 4 5
Yes

1
1000000000
Yes