# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
647180 | beaconmc | Growing Vegetables is Fun 4 (JOI21_ho_t1) | C++14 | 0 ms | 0 KiB |
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()))
a = [0]
b = [0]
for i in range(len(lis)-1):
a.append(a[-1] + max(0,lis[i]-lis[i+1]+1))
lis.reverse()
for i in range(len(lis)-1):
b.append(b[-1] + max(0,lis[i]-lis[i+1]+1))
b.reverse()
print(min([max([a[i],b[i]]) for i in range(len(a))]))