We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent aa11a28 commit 6733046Copy full SHA for 6733046
JHLEE325/202507/22 BOJ G4 카드 정렬하기.md
@@ -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