백준 11286번: 절댓값 힙 #Python

ColorlessDia·2025년 2월 4일

algorithm/baekjoon

목록 보기
443/808
import sys
import heapq as hq

input = sys.stdin.readline

heap = []

N = int(input())

for _ in range(N):
    x = int(input())
        
    if 0 < x:
        hq.heappush(heap, (x, x))
        continue

    if x < 0:
        hq.heappush(heap, (-x, x))
        continue
    
    if len(heap) != 0:
        pop_item = hq.heappop(heap)[1]

        print(pop_item)
        continue
    
    print(0)

0개의 댓글