쏘ing
[Python] 백준 1927 최소 힙 본문
https://www.acmicpc.net/problem/1927


풀이
import heapq
import sys
num = int(sys.stdin.readline().rstrip())
num_list = []
for _ in range (num):
temp = int(sys.stdin.readline().rstrip())
# 입력이 0일 때
if temp == 0:
# 배열이 비어있을 경우 0 출력
if len(num_list) == 0:
print(0)
# 아니면 작은 값 출력
else:
print(heapq.heappop(num_list))
# 0이 아닐 경우 배열에 넣기
else:
heapq.heappush(num_list, temp)
'알고리즘 > CLASS 3' 카테고리의 다른 글
[Python] 백준 11726 2 x n 타일링 (0) | 2022.02.26 |
---|---|
[Python] 백준 11286 절댓값 힙 (0) | 2022.02.23 |
[Python] 백준 9461 파도반 수열 (0) | 2022.02.21 |
[Python] 백준 1003 피보나치 함수 (0) | 2022.02.21 |
[Python] 백준 1463 1로 만들기 (0) | 2022.02.21 |