Algorithm/백준
[백준] 11279 최대 힙
sunnyshiny
2023. 7. 11. 12:27
728x90
https://www.acmicpc.net/problem/11279
11279번: 최대 힙
첫째 줄에 연산의 개수 N(1 ≤ N ≤ 100,000)이 주어진다. 다음 N개의 줄에는 연산에 대한 정보를 나타내는 정수 x가 주어진다. 만약 x가 자연수라면 배열에 x라는 값을 넣는(추가하는) 연산이고, x가 0
www.acmicpc.net
import sys
import heapq
input = sys.stdin.readline
n = int(input())
heap = []
for _ in range(n):
x = int(input())
if x !=0:
heapq.heappush(heap, (-x))
else:
try:
print(-1* heapq.heappop(heap))
except:
print(0)
728x90