https://www.acmicpc.net/problem/11501
import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
n = int(input()) # 날의 수
cost = list(map(int,input().split())) # 날 별 주가들
ans = 0 # 최대 이익
max_cost = cost[-1]
for i in range(n-1,0,-1):
if max_cost > cost[i-1]:
ans += max_cost - cost[i-1]
else:
max_cost = cost[i-1]
print(ans)
'백준' 카테고리의 다른 글
백준 2493. 탑 (0) | 2025.02.23 |
---|---|
백준 16928. 뱀과 사다리 게임 (0) | 2025.02.14 |
백준 20006. 랭킹전 대기열 (0) | 2025.02.06 |
백준 20055. 컨테이너 벨트 위의 로봇 (0) | 2025.02.03 |
백준 1927. 최소 힙 (0) | 2025.02.03 |