나의 개발일지

[백준] 1927 최소 힙 [Python, 파이썬] 본문

백준

[백준] 1927 최소 힙 [Python, 파이썬]

YoonJuHan 2024. 1. 3. 09:29

 

from heapq import heappop, heappush
import sys
input = sys.stdin.readline

n = int(input())

heap = []
for _ in range(n):
    x = int(input())
    if not heap and x == 0:
        print(0)
    elif x > 0:
        heappush(heap, x)
    else:
        print(heappop(heap))
Comments