112861 백준 11286 절댓값 힙 import heapq, sys input = sys.stdin.readline min_heap = [] max_heap = [] for _ in range(int(input())) : num = int(input()) if num > 0 : heapq.heappush(min_heap, num) elif num < 0 : heapq.heappush(max_heap, -num) else : if len(min_heap) == 0 : if len(max_heap) == 0 : print(0) else : print(-heapq.heappop(max_heap)) elif len(max_heap) == 0 or min_heap[0] < max_heap[0] : print(heapq.heappop(min_heap.. 2022. 6. 13. 이전 1 다음