풀이import sysimport heapqinput = sys.stdin.readlinen = int(input().rstrip())heap = []for _ in range(n): x = int(input().rstrip()) if x == 0: if len(heap) > 0: # 가장 작은 값 출력 m = heapq.heappop(heap) print(m) else: print(0) else: heapq.heappush(heap, x) heap 기초 문제