| ps | |
|---|---|
| 링크 | acmicpc.net/… |
| 출처 | BOJ |
| 문제 번호 | 11501 |
| 문제명 | 주식 |
| 레벨 | 실버 2 |
| 분류 |
그리디 |
| 시간복잡도 | O(t*n) |
| 인풋사이즈 | t<=?, n<=1,000,000 |
| 사용한 언어 | Python |
| 제출기록 | 169696KB / 3224ms |
| 최고기록 | 2584ms |
| 해결날짜 | 2021/12/31 |
"""Solution code for "BOJ 11501. 주식".
- Problem link: https://www.acmicpc.net/problem/11501
- Solution link: http://www.teferi.net/ps/problems/boj/11501
Tags: [Greedy]
"""
def main():
T = int(input())
for _ in range(T):
N = int(input()) # pylint: disable=unused-variable
prices = [int(x) for x in input().split()]
answer = 0
max_price = 0
for price in reversed(prices):
if price <= max_price:
answer += max_price - price
else:
max_price = price
print(answer)
if __name__ == '__main__':
main()