Skip to content

Commit 244d37d

Browse files
committed
[BOJ] 1927 최소 힙(S2)
1 parent 8d73be1 commit 244d37d

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

심수연/3주차/260112.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# https://www.acmicpc.net/problem/1927
2+
3+
import sys
4+
import heapq
5+
6+
input = sys.stdin.readline
7+
8+
N = int(input())
9+
10+
# 가장 작은 값 출력하고 배열에서 제거 -> min heap
11+
hq = []
12+
13+
for _ in range(N):
14+
num = int(input())
15+
if num == 0:
16+
if not hq: # hq 가 없다면 0 출력
17+
min_num = 0
18+
else:
19+
min_num = heapq.heappop(hq) # 배열에서 가장 작은 값 출력
20+
print(min_num)
21+
else: # 정수 x 라면 배열에 추가
22+
heapq.heappush(hq, num)
23+

0 commit comments

Comments
 (0)