Skip to content

Commit 6733046

Browse files
authored
[20250722] BOJ / G4 / 카드 정렬하기 / 이준희
1 parent aa11a28 commit 6733046

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
```java
2+
import java.io.BufferedReader;
3+
import java.io.InputStreamReader;
4+
import java.util.*;
5+
6+
public class Main {
7+
8+
public static void main(String[] args) throws Exception {
9+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
10+
StringTokenizer st;
11+
12+
int n = Integer.parseInt(br.readLine());
13+
Queue<Integer> q = new PriorityQueue<>();
14+
15+
for (int i = 0; i < n; i++) {
16+
q.add(Integer.parseInt(br.readLine()));
17+
}
18+
19+
int result = 0;
20+
while (q.size() != 1) {
21+
int a = q.poll();
22+
int b = q.poll();
23+
result += a + b;
24+
q.add(a + b);
25+
}
26+
27+
System.out.println(result);
28+
}
29+
}
30+
31+
```

0 commit comments

Comments
 (0)