쏘ing

[Python] 백준 11279 최대 힙 본문

알고리즘/CLASS 3

[Python] 백준 11279 최대 힙

한민민 2022. 2. 21. 16:03

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

풀이

import heapq
import sys
num = int(sys.stdin.readline().rstrip())

num_list = []

for _ in range(num):
    temp = int(sys.stdin.readline().rstrip())
	
    # 최대 힙
    heapq.heappush(num_list, (-temp, temp))
        
    if temp == 0:
        print(heapq.heappop(num_list)[1])
Comments