반응형
import sys
import heapq
N = int(sys.stdin.readline())
X = [int(sys.stdin.readline()) for _ in range(N)]
heap = []
for x in X:
if x == 0:
if not heap:
print(0)
else:
print(heapq.heappop(heap))
else:
heapq.heappush(heap, x)
반응형