1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
import heapq
n, m = map(int, input().split())
a = list(map(int, input().split()))
heapq.heapify(a)
for i in range(m):
first = heapq.heappop(a)
second = heapq.heappop(a)
heapq.heappush(a, first+second)
heapq.heappush(a, first+second)
sum(a)
|
cs |
너무 순한맛이라 설명생략.