BOJ - 11279 - 최대 힙

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/11279

Categories:

Updated:

Leave a comment