Algorithm/BaekJoon
[백준/Python] 15903번 - 카드 합체 놀이
빵빵0
2023. 9. 1. 02:24
import sys
input = sys.stdin.readline
import heapq
n, m = map(int, input().split())
cards = [i for i in map(int, input().split())]
heapq.heapify(cards)
for _ in range(m):
x = heapq.heappop(cards)
y = heapq.heappop(cards)
heapq.heappush(cards, x+y)
heapq.heappush(cards, x+y)
print(sum(cards))
우선 순위 큐를 이용하면 쉽게 풀 수 있는 문제였다!