[백준] 2847번: 게임을 만든 동준이

whitehousechef·2023년 10월 5일
0

https://www.acmicpc.net/problem/2847

initial

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)

revisited jan 24th

yep straightforward traversing from the back of the list

complexity

o(n) time and space complexity

0개의 댓글