practivceAlgorithm/swexpertacademy
[SWEA][Python] 1859 백만장자 프로젝트
findTheValue
2021. 8. 15. 18:52
뒤에서부터 작은걸 만나면 그 차이만큼 결과에 더해줍니다.
for test in range(1,int(input())+1):
N = int(input())
prices = list(map(int, input().split()))
answer = 0
max_price = 0
for j in range(N-1,-1,-1):
if max_price > prices[j]:
answer += max_price - prices[j]
else:
max_price = prices[j]
print(f'#{test} {answer}')