최소 힙

last update: 2021.08.12.Thu

1927 최소 힙, Silver 1

Memory 35908KB, Time 188ms


import sys, heapq

n = int(input())
array = list(int(sys.stdin.readline().strip()) for _ in range(n))
result = []

for i in range(0, n):
    if array[i] == 0 and len(result) == 0:
        print(0)
    elif array[i] != 0 :
        heapq.heappush(result, array[i])
    elif array[i] == 0:
        temp = heapq.heappop(result)
        print(temp)