We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 8d73be1 commit 244d37dCopy full SHA for 244d37d
1 file changed
심수연/3주차/260112.py
@@ -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