Skip to content

Commit 9a1853d

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

File tree

1 file changed

+33
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)