-
[백준] 11279. 최대힙코테 준비/Heap 2023. 1. 10. 01:46
import sys import heapq n=int(sys.stdin.readline()) maxheap=[] for i in range(n): x=int(sys.stdin.readline()) if x==0: if len(maxheap)==0: print("0") else: num=heapq.heappop(maxheap) print(-num) #출력해줄때만 마이너스 붙여서 출력 else: heapq.heappush(maxheap,-x) #x대신 -x를 넣어주면 최댓값이 최솟값이 됨
'코테 준비 > Heap' 카테고리의 다른 글
[프로그래머스] 더 맵게 (0) 2023.01.25 [백준] 11286. 절대값 힙 (0) 2023.01.10 [백준] 1972. 최소힙 (heapq 알아두기) (0) 2023.01.10