BOJ - 1927 - 최소 힙

Updated:

import sys
import heapq

def solution():
    N = int(input())
    heap = []
    ret = []

    for i in range(N):
        X = int(sys.stdin.readline())
        
        if X == 0:
            if len(heap) > 0:
                ret.append(heapq.heappop(heap))
            else:
                ret.append(0)
            continue
        
        heapq.heappush(heap, X)

    for i in ret:
        print(i)
        
solution()

https://www.acmicpc.net/problem/1927

Categories:

Updated:

Leave a comment