Bad_Programist

Untitled

Jan 27th, 2019
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.55 KB | None | 0 0
  1. N = int(input())
  2. A = list(map(int, input().split()))
  3. B = []
  4. T = []
  5. res = 'YES'
  6. n = 1
  7. while len(A) != 0:
  8.     if n in A:
  9.         k = A.index(n)
  10.         B.append(n)
  11.         N = A[:k + 1]
  12.         for i in N:
  13.             A.remove(i)
  14.         T += N[:k]
  15.         n += 1
  16.     else:
  17.         k = T.index(n)
  18.         if k != len(T) - 1:
  19.             res = 'NO'
  20.             break
  21.         else:
  22.             T.pop()
  23.             B.append(n)
  24.             n += 1
  25. if res == 'YES' and T == sorted(T, reverse = True):
  26.     res = 'YES'
  27. else:
  28.     res = 'NO'
  29. print(res)
Advertisement
Add Comment
Please, Sign In to add comment