python

파이썬에서 heapq로 최소 힙 - 우선순위 큐 구현

언어 수집가 2021. 2. 25. 14:09
import sys
import heapq
n = int(input())
arr = []
for i in range(n):
command = int(sys.stdin.readline().rstrip())
if command != 0:
heapq.heappush(arr, command)
else:
if arr:
print(heapq.heappop(arr))
else:
print(0)