Skip to content

Commit b66b43b

Browse files
committed
[BOJ] 11286 절댓값 힙 (S1)
1 parent 77e943a commit b66b43b

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

심수연/3주차/260113.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# https://www.acmicpc.net/problem/11286
2+
3+
import sys
4+
import heapq
5+
input = sys.stdin.readline
6+
7+
N = int(input())
8+
9+
hq = []
10+
11+
for _ in range(N):
12+
num = int(input())
13+
if num == 0:
14+
if not hq:
15+
min_num = 0
16+
else:
17+
min_num = heapq.heappop(hq)[1] # 최소 힙 -> 튜플을 pop. 실제 값 (idx = 1) 을 min_num에 대입
18+
print(min_num)
19+
else:
20+
heapq.heappush(hq, (abs(num), num)) # 절댓값 최소 힙. 기존 값을 같이 튜플로 넣어줌

0 commit comments

Comments
 (0)