Skip to content

Commit 90c8a44

Browse files
authored
[BOJ] 1715 카드 정렬하기 (G4)
1 parent cae4918 commit 90c8a44

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

정건우/10주차/260306.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//https://www.acmicpc.net/problem/1715
2+
import java.io.BufferedReader;
3+
import java.io.IOException;
4+
import java.io.InputStreamReader;
5+
import java.util.PriorityQueue;
6+
7+
public class BOJ_G4_1715_카드정렬하기 {
8+
public static void main(String[] args) throws IOException {
9+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
10+
11+
int N = Integer.parseInt(br.readLine());
12+
13+
if(N == 1) {
14+
System.out.println(0);
15+
return;
16+
}
17+
18+
PriorityQueue<Integer> pq = new PriorityQueue<>();
19+
20+
for (int i = 0; i < N; i++) {
21+
pq.add(Integer.parseInt(br.readLine()));
22+
}
23+
24+
int ans = 0;
25+
26+
while (pq.size() >= 2) {
27+
int a = pq.poll();
28+
int b = pq.poll();
29+
30+
pq.add(a+b);
31+
ans += a+b;
32+
}
33+
34+
System.out.println(ans);
35+
36+
}
37+
}

0 commit comments

Comments
 (0)