컴공생의 다이어리

[파이썬, Python] 백준 11286번 : 절댓값 힙 본문

Development/Algorithm & Coding Test

[파이썬, Python] 백준 11286번 : 절댓값 힙

컴공 K 2022. 5. 15. 00:01

백준 11286번 : 절댓값 힙

(문제 바로가기)

 

 

내 코드

import heapq, sys

n = int(input())
heap = []

for _ in range(n):
    num = int(sys.stdin.readline())
    if num == 0:
        if heap:
            print(heapq.heappop(heap)[1])
        else:
            print(0)
    else:
        heapq.heappush(heap, (abs(num), num))

 

 

728x90
Comments