BOJ11279 최대힙

randi65535·2020년 12월 6일
0

파이썬의 heapq는 최소힙이기 때문에 값을 -로 치환해주면 최대힙으로 이용할 수 있다.

import heapq
import sys
input = sys.stdin.readline

N = int(input())

hq = []
for i in range(N):
	n = int(input())

	if n == 0:
		if not hq:
			print(0)
		else:
			print(-1*heapq.heappop(hq))
	else:
		heapq.heappush(hq, -1*n)
profile
unsinged int 8byte-1

0개의 댓글

관련 채용 정보