본문 바로가기
> 알고리즘 문제 풀이/BOJ

*1927-최소 힙 (python, 파이썬)

by bky373 2020. 10. 21.
import heapq
import sys

N = int(input())
heap = []

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)
        

댓글