We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 77e943a commit b66b43bCopy full SHA for b66b43b
1 file changed
심수연/3주차/260113.py
@@ -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
20
+ heapq.heappush(hq, (abs(num), num)) # 절댓값 최소 힙. 기존 값을 같이 튜플로 넣어줌
0 commit comments