15903번: 카드 합체 놀이
첫 번째 줄에 카드의 개수를 나타내는 수 n(2 ≤ n ≤ 1,000)과 카드 합체를 몇 번 하는지를 나타내는 수 m(0 ≤ m ≤ 15×n)이 주어진다. 두 번째 줄에 맨 처음 카드의 상태를 나타내는 n개의 자연수 a1,
www.acmicpc.net
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 |
너무 순한맛이라 설명생략.