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):
import sys

N = int(input())
a = list(map(int,input().split()))
l = []
for i in range(N-1):
    l.append(a[i+1]-a[i])
if any(i<=-2 for i in l):
    print("No")
for i in range(len(l)):
    total = l[i]
    for k in range(1,len(l)):
        if total < 0:
            total += l[k]
            if total <=-2:
                print("No")
                sys.exit()
        else:
            break
print("Yes")

import sys
for i in range(N-1):
    l.append(a[i+1]-a[i])
if any(i<=-2 for i in l):
    print("No")
for i in range(N-1):
    total = l[i]
    for k in range(1,N-1):
        if total <=0:
            total += l[k]
            if k == N-2:
                print("No")
                sys.exit()
        else:
            break
print("Yes")

N = int(input())
a = list(map(int,input().split()))
l = []

import sys
for i in range(N-1):
    l.append(a[i+1]-a[i])
if any(i<=-2 for i in l):
    print("No")
for i in range(N-1):
    total = l[i]
    for k in range(1,N-1):
        if total <=0:
            total += l[k]
            if k == N-2:
                print("No")
                sys.exit()
        else:
            break
print("Yes")

N = int(input())
a = list(map(int,input().split()))
l = []

import sys
for i in range(N-1):
    l.append(a[i+1]-a[i])
if any(i<=-2 for i in l):
    print("No")
for i in range(N-1):
    total = l[i]
    for k in range(1,N-1):
        if total <　0:
            total += l[k]
            if k == N-2:
                print("No")
                sys.exit()
        else:
            break
print("Yes")


import sys
N = int(input())
a = list(map(int,input().split()))
l = []
for i in range(N-1):
    l.append(a[i+1]-a[i])
if any(i<=-2 for i in l):
    print("No")
for i in range(N-1):
    total = l[i]
    for k in range(1,N-1):
        if total <0:
            total += l[k]
            if k == N-2:
                print("No")
                sys.exit()
        else:
            break
print("Yes")

import sys

N = int(input())
a = list(map(int,input().split()))
l = []
for i in range(N-1):
    l.append(a[i+1]-a[i])
if any(i<=-2 for i in l):
    print("No")
for i in range(N-1):
    total = l[i]
    for k in range(1,N-1):
        if total <0:
            total += l[k]
            if total <=-2:
                print("No")
                sys.exit()
        else:
            break
print("Yes")


N = int(input())
a = list(map(int,input().split()))
l = []
for i in range(N-1):
    if a[i+1]-a[i] != 0:
        l.append(a[i+1]-a[i])
# print(l)
if any(i<=-2 for i in l):
    print("No")
    exit()
# while 0 in l:
#     l.remove(0)
# # print(l)
for i in range(len(l)-1):
    if l[i] == -1 and l[i+1] == -1:
        print("No")
        exit()
print("Yes")

Verdicts: Wrong Answer

Runtime Error

Wrong Answer

Runtime Error

Wrong Answer

Wrong Answer

Accepted