from heapq import heappop, heapify
nums = [3,2,1,5,6,4]
k = 2
nums = [i * -1 for i in nums]
# 최소힙을 최대힙처럼 사용하기 위함
heapify(nums)
for _ in range(k):
output = heappop(nums) * -1
return output
from heapq import heappush, heappop
nums = [3,2,1,5,6,4]
k = 2
heap = []
# 최소힙을 최대힙처럼 사용하기 위함
for _ in range(k):
heappush(heap, (-i, i))
# [(-6, 6), (-5, 5), (-4, 4), (-5, 5), (-2, 2), (-3, 3), (-3, 3), (-1, 1), (-2, 2)]
for _ in range(k):
output = heappop(heap)[1]
print(output)