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

힙에 저장할 때 튜플 형식으로 절댓값과 부호를 함께 넣어주었다. (-는 False, +는 True로)
부호를 넣어준 이유는 -1, 1이 들어갔을 때 문제에서 가장 작은 값이 여러개라면 가장 작은 수를 출력하라고 했으므로 -1을 출력해야한다.
import sys
import heapq
input = sys.stdin.readline
"""
최소힙
절댓값이 가장 작은 값 출력
절댓값이 가장 작은 값이 여러개라면 가장 작은 수 출력
"""
n = int(input())
heap = []
for _ in range(n):
x = int(input())
if x == 0:
if not heap:
print(0)
else:
y = heapq.heappop(heap)
if y[1] == False:
print(-y[0])
else:
print(y[0])
continue
if x > 0:
temp = True
else:
temp = False
x = -x
heapq.heappush(heap,(x,temp)) # 부호와 같이 저장