https://www.codetree.ai/missions/8/problems/process-numeric-commands-6/description
import sys
from heapq import heappush, heappop
input = sys.stdin.readline
# 최대힙으로
heap = []
n = int(input())
for _ in range(n):
cmd = input().rstrip().split()
if cmd[0] == 'push':
heappush(heap, -int(cmd[1]))
elif cmd[0] == 'pop':
top = heappop(heap)
print(-top)
elif cmd[0] == 'size':
print(len(heap))
elif cmd[0] == 'empty':
if heap:
print(0)
else:
print(1)
elif cmd[0] == 'top':
print(-heap[0])
728x90
반응형
'🔻PS > Codetree' 카테고리의 다른 글
[Codetree] 빙하 Python (0) | 2024.09.02 |
---|---|
[Codetree] 큰 숫자만 계속 고르기 Python (0) | 2024.08.09 |
[Codetree] 가장 많은 데이터 Python (0) | 2024.08.08 |
[Codetree] 가장 먼저 나오는 숫자 Python (0) | 2024.08.08 |
[Codetree] 가장 먼저 나오는 숫자 Python (0) | 2024.08.08 |