This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
n = int(input())
lis = list(map(int, input().split()))
suslis = list(lis)
fwd = [0 for i in range(n)]
bkwd = [0 for i in range(n)]
cur = 0
for i in range(1,n):
if lis[i]+cur <= lis[i-1]:
cur = lis[i-1] - lis[i] + 1
lis[i] += cur
fwd[i] = cur
lis = list(suslis)
cur = 0
for i in range(n-2, -1, -1):
if lis[i]+cur <= lis[i+1]:
cur = lis[i+1] - lis[i] + 1
lis[i] += cur
bkwd[i] = cur
ans = float("inf")
for i in range(n):
ans = min(ans, max(fwd[i], bkwd[i]))
print(ans)
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |