Problem: 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.

Submission attempts (in order):
n = int(input())
h = [0]
h.extend(list(map(int, input().split())))
max = 0

for i in range(n + 1)[1:]:
    if h[i] >= max >= h[i - 1]:
        max = h[i]
    if max - h[i] >= 2:
        print("NO")
        exit()

print("YES")


n = int(input())
h = list(map(int, input().split()))
max = 0

for i in range(n)[1:]:
    if h[i] > h[i - 1] > max:
        max = h[i]
    if max - h[i] >= 2:
        print("NO")
        exit()

print("YES")


n = int(input())
h = [0, ]
h.extend(list(map(int, input().split())))
vh = [0, ]

for i in range(n + 1)[1:]:
    vh.append(vh[i - 1])
    if h[i] < h[i - 1]:
        vh[i] += h[i - 1] - h[i]

flag = False
for j in range(n + 1):
    if vh[j] > 1:
        flag = True
print(vh)
if flag:
    print("NO")
else:
    print("YES")


n = int(input())
h = [0]
h.extend(list(map(int, input().split())))
max = 0
flag = False

for i in range(n + 1)[1:]:
    if h[i] >= h[i - 1]:
        max = h[i]
    if abs(max - h[i]) >= 2:
        print("NO")
        exit()

print("YES")


n = int(input())
h = list(map(int, input().split()))
uu = 0

for i in range(1, n):
    if h[i] > h[i - 1] and h[i] > uu:
        uu = h[i]
    if uu - h[i] > 1:
        print("NO")
        exit()

print("YES")


n = int(input())
h = [0]
h.extend((map(int, input().split())))
vh = [0]

for i in range(n + 1)[1:]:
    vh.append(vh[i - 1])
    if h[i] < h[i - 1]:
        vh[i] += h[i - 1] - h[i]

flag = False
for j in range(n + 1):
    if vh[j] > 1:
        flag = True

if flag:
    print("NO")
else:
    print("YES")


n = int(input())
h = list(map(int, input().split()))

for i in range(1, n):
    if h[i] < h[i - 1]:
        h[i] -= 1
        if h[i] < h[i - 1]:
            print("NO")
            exit()

print("YES")


n = int(input())
h = list(map(int, input().split()))

for i in range(1, n):
    if h[i] < h[i - 1]:
        h[i - 1] -= 1
        if h[i] < h[i - 1]:
            print("NO")
            exit()

print("YES")


n = int(input())
h = [0]
h.extend(list(map(int, input().split())))
max = 0
flag = False

for i in range(n + 1)[1:]:
    if h[i] >= h[i - 1]:
        max = h[i]
    if max - h[i] >= 2:
        print("NO")
        exit()

print("YES")


n = int(input())
h = [0]
h.extend(list(map(int, input().split())))
max = 0
flag = False

for i in range(n + 1):
    if h[i] > h[i - 1]:
        max = h[i]
    if max - h[i] >= 2:
        flag = True

if flag:
    print("NO")
else:
    print("YES")


n = int(input())
h = [0]
h.extend(list(map(int, input().split())))
flag = False

for i in range(n + 1)[1:]:
    if h[i] < h[i - 1]:
        print("NO")
        exit()
    if h[i] > h[i - 1]:
        h[i] -= 1

print("YES")


n = int(input())
h = list(map(int, input().split()))
flag = False

for i in range(n)[1:]:
    if h[i] < h[i - 1]:
        print("NO")
        exit()
    if h[i] > h[i - 1]:
        h[i] -= 1

print("YES")


n = int(input())
h = list(map(int, input().split()))

for i in range(n, 1):
    if h[i] < h[i - 1]:
        h[i] -= 1
        if h[i] < h[i - 1]:
            print("NO")
            exit()
            
print("YES")


n = int(input())
h = list(map(int, input().split()))
max = 0

for i in range(n):
    if i == 0:
        continue

    if h[i] > h[i - 1]:
        if h[i] > max:
            max = h[i]

    if max - h[i] >= 2:
        print("NO")
        exit()

print("YES")


n = int(input())
h = list(map(int, input().split()))

for i in range(n)[1:]:
    if h[i] < h[i - 1]:
        h[i] -= 1
    if h[i] < h[i - 1]:
        print("NO")
        exit()

print("YES")

n = int(input())
h = list(map(int, input().split()))
max = 0

for i in range(n)[1:]:
    if h[i] > max:
        max = h[i]
    if max - h[i] >= 2:
        print("NO")
        exit()

print("YES")


n = int(input())
h = [0]
h.extend(list(map(int, input().split())))
max = 0
flag = False

for i in range(n + 1):
    if h[i] > h[i - 1]:
        max = h[i]
    if max - h[i] >= 2:
        flag = True

if flag:
    print("No")
else:
    print("Yes")


Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Accepted