백준 11279번: 최대 힙 #Python

ColorlessDia·2025년 2월 2일

algorithm/baekjoon

목록 보기
441/807
import sys
import heapq as hq

input = sys.stdin.readline

heap = []

N = int(input())

for _ in range(N):
    x = int(input())

    if 0 < x:
        hq.heappush(heap, -x)
        continue
    
    if 0 < len(heap):
        pop_item = -hq.heappop(heap)

        print(pop_item)
        continue
    
    print(0)

0개의 댓글