Skip to content

Commit d3cc30a

Browse files
committed
2 parents 3b02976 + df7fa3d commit d3cc30a

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

정건우/3주차/260113.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//https://www.acmicpc.net/problem/14241
2+
import java.io.BufferedReader;
3+
import java.io.IOException;
4+
import java.io.InputStreamReader;
5+
import java.util.Collections;
6+
import java.util.PriorityQueue;
7+
import java.util.StringTokenizer;
8+
9+
public class BOJ_S3_14241_슬라임합치기 {
10+
public static void main(String[] args) throws IOException {
11+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
12+
int N = Integer.parseInt(br.readLine());
13+
14+
PriorityQueue<Integer> pq = new PriorityQueue<>(Collections.reverseOrder());
15+
16+
StringTokenizer st = new StringTokenizer(br.readLine());
17+
for (int i = 0; i < N; i++) {
18+
pq.add(Integer.parseInt(st.nextToken()));
19+
}
20+
21+
int ans = 0;
22+
23+
while (pq.size() >= 2) {
24+
int x = pq.poll();
25+
int y = pq.poll();
26+
27+
ans += x * y;
28+
pq.add(x+y);
29+
}
30+
31+
System.out.println(ans);
32+
33+
}
34+
}

0 commit comments

Comments
 (0)