-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0426.py
More file actions
27 lines (26 loc) · 677 Bytes
/
0426.py
File metadata and controls
27 lines (26 loc) · 677 Bytes
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
from collections import deque
from heapq import heappop, heappush
def solution(N,arr):
rep = True
heap = []
answer = 0
compare1 = 0
compare2 = 0
candidate = deque(arr)
criminal = candidate.popleft()
candidate2 = list(candidate)
for num in candidate2:
heappush(heap, (-num, num))
while rep == False:
if compare1 == 0:
compare1 = heappop(heap)
else:
compare1 = compare2
compare2 = heappop(heap)
temp = compare1 - compare2
if (criminal + temp) > compare2:
rep = True
answer += temp
else:
answer += temp
return answer