💡 Python 3
1927 최소 힙 [Link]
처음에
input()
으로 시도했는데 시간 초과가 됐다.
그래서sys
모듈을 이용해 입력을 받았더니 통과가 되었다.
제한 시간에 유의하자.
import heapq
import sys
heap = []
n = int(sys.stdin.readline())
for _ in range(n):
num = int(sys.stdin.readline())
if num == 0:
if heap: print(heapq.heappop(heap))
else: print(0)
else: heapq.heappush(heap, num)