BOJ - 11286 - 절댓값 힙

Updated:

import sys
import heapq

def solution():

    heap = []
    N = int(input())
    for _ in range(N):
        number = int(sys.stdin.readline())

        if number == 0:
            try:
                print(heapq.heappop(heap)[1])
            except:
                print(0)
        else:
            heapq.heappush(heap, (abs(number), number))
solution()

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

Categories:

Updated:

Leave a comment