본문 바로가기

[BOJ] - Python

[백준] 1927 : 최소 힙 python

 

import sys
import heapq

input = sys.stdin.readline

n = int(input())
h = []

for i in range(n):
    x = int(input())
    if x==0:
        # 리스트가 비어있으면 if not 조건이 True가 됨
        if not h:
            print(0)
        else:
            print(heapq.heappop(h))
    else:
        heapq.heappush(h,x)