-
Notifications
You must be signed in to change notification settings - Fork 0
/
p42628.py
27 lines (26 loc) · 824 Bytes
/
p42628.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
# 0:20
import heapq
def solution(operations):
answer = []
max_heap = []
min_heap = []
for o in operations:
s = o.split(" ")
if s[0] == 'I':
heapq.heappush(max_heap, (-int(s[1]), int(s[1])))
heapq.heappush(min_heap, int(s[1]))
elif s[0] == 'D':
if len(max_heap) > 0:
if s[1] == '1':
h = heapq.heappop(max_heap)[1]
index = min_heap.index(h)
del min_heap[index]
elif s[1] == '-1':
h = heapq.heappop(min_heap)
index = max_heap.index((-h, h))
del max_heap[index]
if len(max_heap) > 0:
answer = [max_heap[0][1], min_heap[0]]
else:
answer = [0, 0]
return answer