백준_11279번

정소담·2023년 3월 3일
0

BOJ Short Review

목록 보기
42/44
post-thumbnail

11279번 최대힙

전일 올렸던 최소힙과 비슷한 문제.
최소가 아닌 배열의 가장 큰 값을 출력하는 문제.

import heapq
import sys
input = sys.stdin.readline
heap = []

for _ in range(int(input())):
    n = int(input())
    if n == 0:
        if len(heap) > 0:
            print(heapq.heappop(heap)*-1)
        else:
            print(0)
    else: 
# 음수로 쌓아주고 가장 작은 값 출력시 양수로 바꿔주면 가장 큰 값이 된다.
        heapq.heappush(heap,-n)
profile
Hi ! I'm newbie :)

0개의 댓글