
[11286] 절댓값 힙 (heapq, PriorityQueue)
·
Coding Test/Data Structure
11286번: 절댓값 힙 첫째 줄에 연산의 개수 N(1≤N≤100,000)이 주어진다. 다음 N개의 줄에는 연산에 대한 정보를 나타내는 정수 x가 주어진다. 만약 x가 0이 아니라면 배열에 x라는 값을 넣는(추가하는) 연산이고, x가 0 www.acmicpc.net import sys input=sys.stdin.readline from heapq import heappush, heappop n=int(input()) q = [] for _ in range(n): num=int(input()) if num==0: if len(q) > 0: print(heappop(q)[1]) else: print(0) else: heappush(q, (abs(num), num)) from queue import Prio..