최대 힙

last update: 2021.08.12.Thu

11279 최대 힙, Silver 2

Memory 45380KB, Time 244ms


import heapq, sys

N = int(input())
array = [int(sys.stdin.readline()) for _ in range(N)]
q = []

for i in range(N):
    if array[i] == 0:
        if q == []:
            print(0)
        else:
            result = -heapq.heappop(q)[1]
            print(-result)
    elif array[i] != 0:    
        heapq.heappush(q, (-array[i], array[i]))