본문 바로가기
Beakjoon&프로그래머스/파이썬

[백준/파이썬] 1927번 최소 힙

by 현장 2022. 1. 14.

-코드

import heapq
from sys import stdin
heap = []
for _ in range(int(stdin.readline())):
    n = int(stdin.readline())
    if n == 0:
        if len(heap) == 0:
            print(0)
        else:
            print(heapq.heappop(heap))
    else:
        heapq.heappush(heap, n)