백준 1927 최소 힙

coffeed-cat·2021년 7월 8일
0

알고리즘

목록 보기
11/11

✅ 백준 1927 최소 힙


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

정답.
어제보다 더 쉬웠다!
heapq 사용해서 해결!

import sys
import heapq

n = int(sys.stdin.readline())
heap = []

for i in range(n) :
    num = int(sys.stdin.readline())
    if num == 0 :
        if len(heap) == 0 :
            print(0)
            continue
        else :
            print(heapq.heappop(heap))
            continue
    heapq.heappush(heap,num)
profile
공부중

0개의 댓글