Skip to content

Commit ad2cd3f

Browse files
committed
BOJ_15903 : 카드 합체 놀이
1 parent 90602f8 commit ad2cd3f

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed
+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import java.io.*;
2+
import java.util.*;
3+
4+
public class Main {
5+
6+
public static void main(String[] args) throws IOException {
7+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
8+
String[] input = br.readLine().split(" ");
9+
int n = Integer.parseInt(input[0]);
10+
int m = Integer.parseInt(input[1]);
11+
12+
StringTokenizer st = new StringTokenizer(br.readLine());
13+
long[] cards = new long[n];
14+
for(int i=0; i<n; i++) {
15+
cards[i] = Integer.parseInt(st.nextToken());
16+
}
17+
Arrays.sort(cards);
18+
for(int i=0; i<m; i++) {
19+
mergeCard(cards);
20+
}
21+
long sum = 0;
22+
for(long num : cards) {
23+
sum += num;
24+
}
25+
System.out.println(sum);
26+
}
27+
28+
public static void mergeCard(long[] cards) {
29+
long num = cards[0] + cards[1];
30+
cards[0] = cards[1] = num;
31+
if(cards.length >= 3 && num > cards[2]) {
32+
Arrays.sort(cards);
33+
}
34+
}
35+
}

0 commit comments

Comments
 (0)