Skip to content

Commit a94cda8

Browse files
authored
#3 : 11279_최대 힙
#3 : Week3_예원이티
1 parent a6b7916 commit a94cda8

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

11279_최대 힙.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
else:
23+
#파이썬에서 힙은 최소힙을 따르므로, 최대힙을 구현하기 위해서 *(-1)
24+
heapq.heappush(heap, (-1)*x)

0 commit comments

Comments
 (0)