Untitled

mail@pastecode.io avatar
unknown
python
3 years ago
987 B
5
Indexable
Never
# -*- coding: utf-8 -*-
"""
Created on Tue Mar  8 22:04:27 2022

@author: johnn
"""

def another_rail_problem(B):
    max_so_far = 0
    station = []
    for i in range(len(B)-1):
        if len(station) != 0:
            if B[i] != B[i-1] + 1:
                if B[i] == station[0]:
                    station = []
                else:
                    return 'NO'
        else: station = list(range(max_so_far+1,B[i]))
        print(B[i], station, max_so_far)
        if B[i] > max_so_far: max_so_far = B[i]
    return 'YES'

# T = int(input())
# for _ in range(T):
#     n = int(input())
#     B = list(map(int, input().split()))
#     print(another_rail_problem(B))

# B = [3, 4, 1, 2, 5]
# B = [1, 2, 3, 4, 5]
# B = [5, 4, 3, 2, 1]
# B = [3, 4, 1, 2, 7, 8, 5, 6]          # YES
B = [3, 4, 1, 2, 7, 8, 6, 5]          # NO
# B = [1, 2, 5, 6, 3, 4, 9, 10, 8, 7]   # NO
# B = [2, 1, 5, 6, 3, 4, 9, 10, 7, 8]   # YES
print(another_rail_problem(B))