흠...
import sys
for i in range(int(input())):
stockLen = int(input())
stockData = list(map(int, sys.stdin.readline().split()))
stockData.insert(0, 1000001)
tempStock = [stockData[-1]]
tempVal = stockData[-1]
ans = 0
for i in range(stockLen - 1, -1, -1):
if stockData[i] < tempVal:
tempStock.append(stockData[i])
else:
for j in tempStock:
ans += tempVal - j
tempVal = stockData[i]
tempStock = [tempVal]
print(ans)
'Algorithm > Greedy' 카테고리의 다른 글
[백준] 1541번 잃어버린 괄호 (0) | 2021.01.24 |
---|---|
[백준] 1339번 단어수학 (0) | 2021.01.23 |
[백준] 2812번 크게 만들기 (0) | 2020.11.28 |
[백준] 11508번 2+1 세일 (0) | 2020.10.20 |
[백준] 14241번 슬라임 합치기 (0) | 2020.10.20 |
댓글