문제풀이/백준(Boj) 문제풀이

[백준][자료구조/힙] 11279.최대 힙 (파이썬/Python)

얄루몬 2022. 1. 8. 14:43

import heapq
import sys
input = sys.stdin.readline
n = int(input())
heap = []

for _ in range(n):
    x = int(input())
    if x != 0:
        heapq.heappush(heap,[-x,x])
    else:
        try:
            print(heapq.heappop(heap)[1])
        except:
            print(0)