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 = input()
l = list(map(int, input().split()))

if l.count(0)+ l.count(1) == len(l):
    print("Yes")
else:
    l1 = l[1:]+[0]
    print(l1)
    d = [i-j for (i,j) in zip(l1, l)][:-1] 
    print(d)
    if -2 in d:
        print("1No")
    else:
        s = ''.join(map(str, d)) 
        spl = s.split("-1") 
        print(spl)
        if "" not in spl:
            print("2Yes")
        else:
            if spl[-1] == "" and spl[-2] != "" and spl[-2] != "0" and "" not in spl[:-1]:
                print("3Yes")
            else:
                if "" in spl:
                    print("4No")
                else:
                    y = [int(i) for i in spl]
                    print(y)
                    if 0 in y:
                        print("5No")
                    else:
                        print("6Yes")

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

if l.count(0)+ l.count(1) == len(l):
    print("Yes")
else:
    l1 = l[1:]+[0]
    print(l1)
    d = [i-j for (i,j) in zip(l1, l)][:-1] 
    print(d)
    t = [i for i in d if i <= -2]
    if len(t) >= 1:
        print("No")
    else:
        s = ''.join(map(str, d)) 
        spl = s.split("-1") 
        print(spl)
        if "" not in spl:
            print("Yes")
        else:
            if spl[-1] == "" and spl[-2] != "" and spl[-2] != "0" and "" not in spl[:-1]:
                print("Yes")
            else:
                if "" in spl:
                    print("No")
                else:
                    y = [int(i) for i in spl]
                    print(y)
                    if 0 in y:
                        print("No")
                    else:
                        print("Yes")

n = input()
l = list(map(int, input().split()))
 
if l.count(0)+ l.count(1) == len(l):
    print("Yes")
else:
    l1 = l[1:]+[0]
    print(l1)
    d = [i-j for (i,j) in zip(l1, l)][:-1] 
    print(d)
    if -2 in d:
        print("No")
    else:
        s = ''.join(map(str, d)) 
        spl = s.split("-1") 
        print(spl)
        if "" not in spl:
            print("Yes")
        else:
            if spl[-1] == "" and spl[-2] != "" and spl[-2] != "0" and "" not in spl[:-1]:
                print("Yes")
            else:
                if "" in spl:
                    print("No")
                else:
                    y = [int(i) for i in spl]
                    print(y)
                    if 0 in y:
                        print("No")
                    else:
                        print("Yes")

n = int(input())
l = list(map(int, input().split()))
if n == 1:
    print("Yes")
else:
    l1 = l[1:]+[0]
    d = [i-j for (i,j) in zip(l1, l)][:-1]
    t = [i for i in d if i <= -2]
    if len(t) >= 1:
        print("No")
    else:
        if -1 not in d or d.count(-1)==1:
            print("Yes")
        else:
            p = d.index(-1)
            d = d[p+1:]
            s = ''.join(map(str, d))
            spl = s.split("-1") 
            if "" in spl[:-1]:
                print("No")
            else:
                if spl[-1] == "":
                    spl = [s for s in spl if s != '']
                    y = [int(i) for i in spl]
                    if 0 not in y:
                        print("Yes")
                    else:
                        print("No")
                else:
                    y = [int(i) for i in spl]
                    if 0 in y[:-1]:
                        print("No")
                    else:
                        print("Yes") 

Verdicts: Runtime Error

Runtime Error

Runtime Error

Accepted