We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 48ebe58 commit 0ddbb21Copy full SHA for 0ddbb21
1 file changed
이티예원/11279_최대 힙.py
@@ -0,0 +1,24 @@
1
+import heapq
2
+import sys
3
+
4
+heap = []
5
6
+#연산의 개수 N을 입력받는다
7
+n = int(input())
8
9
+for i in range(n):
10
11
+ #연산에 대한 정보를 나타내는 정수 x가 주어진다
12
+ x = int(sys.stdin.readline())
13
14
+ #x가 0이라면
15
+ if x == 0:
16
+ #배열의 요소가 있는 경우,
17
+ #배열에서 가장 큰 갑을 출력
18
+ if heap:
19
+ print((-1)*heapq.heappop(heap))
20
+ else:
21
+ print(0)
22
23
+ #파이썬에서 힙은 최소힙을 따르므로, 최대힙을 구현하기 위해서 *(-1)
24
+ heapq.heappush(heap, (-1)*x)
0 commit comments