forked from Zy0ung/baekjoon
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.py
50 lines (48 loc) · 1.52 KB
/
main.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
# Authored by : chj3748
# Co-authored by : -
# Link : http://boj.kr/2eb814a8afac4ceab99cbb89db78a2c6
import sys
import heapq
from collections import defaultdict
def input():
return sys.stdin.readline().rstrip()
for T in range(int(input())):
max_q = []
min_q = []
total_ele_cnt = 0
elements_cnt = defaultdict(int)
for _ in range(int(input())):
operator, number = input().split()
if operator == 'I':
number = int(number)
heapq.heappush(max_q, -number)
heapq.heappush(min_q, number)
elements_cnt[number] += 1
total_ele_cnt += 1
else:
if total_ele_cnt > 0:
if number == '1':
while True:
del_num = -heapq.heappop(max_q)
if elements_cnt[del_num] != 0:
elements_cnt[del_num] -= 1
break
else:
while True:
del_num = heapq.heappop(min_q)
if elements_cnt[del_num] != 0:
elements_cnt[del_num] -= 1
break
total_ele_cnt -= 1
if total_ele_cnt:
while True:
max_v = -heapq.heappop(max_q)
if elements_cnt[max_v] != 0:
break
while True:
min_v = heapq.heappop(min_q)
if elements_cnt[min_v] != 0:
break
print(max_v, min_v)
else:
print('EMPTY')