-
Notifications
You must be signed in to change notification settings - Fork 0
/
11501 주식.py
40 lines (39 loc) · 971 Bytes
/
11501 주식.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
import sys
import copy
input = sys.stdin.readline
for _ in range(int(input())):
dic = {}
n = int(input())
arr = list(map(int,input().split()))
arr2 = copy.deepcopy(arr)
arr2.sort()
for i in arr:
if i in dic:
dic[i] +=1
else:
dic[i] =1
MaxValue = arr2[-1]
point = 0
result = 0
while True:
if point == len(arr)-1:
break
if arr[point] != MaxValue:
result += MaxValue - arr[point]
dic[arr[point]] -=1
point +=1
else:
dic[arr[point]] -=1
while True:
if len(arr2) == 0:
break
arr2.pop()
if len(arr2) == 0:
break
MaxValue = arr2[-1]
if dic[MaxValue] == 0:
continue
else:
point+=1
break
print(result)