1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | import sys n = int(sys.stdin.readline().rstrip()) me = int(sys.stdin.readline().rstrip()) arr = [] result = 0 for _ in range(n – 1): t = int(sys.stdin.readline().rstrip()) if t >= me: arr.append(t) if len(arr) != 0: arr.sort(reverse=True) while arr[0] >= me: arr[0] –= 1 me += 1 result += 1 if len(arr) > 1 and arr[0] < arr[1]: arr.sort(reverse=True) print(result) | cs |