백준 11286번

Hyuntae Jung·2022년 8월 29일
0

Algorithm

목록 보기
7/17
post-thumbnail
import heapq as hq
import sys


# input = sys.stdin.readline # input()사용시 입력시간만으로도 시간초과 
# pq = []
# for _ in range(int(input())):
#     x = int(input())  
#     if x:
#         hq.heappush(pq, (abs(x), x)) # 절대값이 작은것을 Root node에 넣을 거임
#     else:
#       print(hq.heapop(pq)[1] if pq else 0)


import sys
import heapq

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

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

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

0개의 댓글