https://www.acmicpc.net/problem/2847
So we want to have an increasing value list. I implemented just like how a human would solve it. I started from the back of the list and implemented it.
n = int(input())
lst = [int(input()) for _ in range(n)]
ans=0
for i in range(len(lst)-2,-1,-1):
if lst[i]>=lst[i+1]:
ans+=lst[i] - lst[i+1] +1
lst[i] = lst[i+1] -1
print(ans)
yep straightforward traversing from the back of the list
o(n) time and space complexity