-
Notifications
You must be signed in to change notification settings - Fork 0
/
boj_11501_greedy.py
71 lines (53 loc) · 1.46 KB
/
boj_11501_greedy.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# import sys
# from collections import deque
# input = sys.stdin.readline
# n = int(input())
# res_list = []
# for i in range(n):
# case_length = int(input())
# sum = 0
# que = deque(list(map(int, input().rstrip().split(" "))))
# while len(que) != 0:
# temp_list = []
# max_num = max(que)
# while len(que) != 0:
# num = que.popleft()
# if num == max_num:
# for k in temp_list:
# sum += max_num - k
# break
# else:
# temp_list.append(num)
# res_list.append(sum)
# for res in res_list:
# print(res)
import sys
from collections import deque
input = sys.stdin.readline
n = int(input())
res_list = []
case_length_list = []
stock_total = []
for i in range(n):
case_length = int(input())
case_length_list.append(case_length)
stock_list = list(map(int, input().rstrip().split(" ")))
stock_total.append(stock_list)
for i in range(n):
c_length = case_length_list[i]
stocks = stock_total[i]
sum = 0
cur_pos = len(stocks) - 1
while cur_pos >= 0:
max_num = max(stocks[cur_pos:])
while cur_pos >= 0:
num = stocks[cur_pos]
if num == max_num:
break
else:
sum += max_num - num
cur_pos -= 1
cur_pos -= 1
res_list.append(sum)
for res in res_list:
print(res)