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 31121c0 commit 4e47aedCopy full SHA for 4e47aed
Seol-JY/202507/02 BOJ G4 카드 정렬하기.md
@@ -0,0 +1,30 @@
1
+```java
2
+import java.io.BufferedReader;
3
+import java.io.InputStreamReader;
4
+import java.io.IOException;
5
+import java.util.PriorityQueue;
6
+
7
+public class Main {
8
+ public static void main(String[] args) throws IOException {
9
+ BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
10
+ int n = Integer.parseInt(br.readLine());
11
12
+ PriorityQueue<Long> pq = new PriorityQueue<>();
13
+ for (int i = 0; i < n; i++) {
14
+ pq.add(Long.parseLong(br.readLine()));
15
+ }
16
17
+ long total = 0;
18
+ while (pq.size() > 1) {
19
+ long a = pq.poll();
20
+ long b = pq.poll();
21
+ long sum = a + b;
22
+ total += sum;
23
+ pq.add(sum);
24
25
26
+ System.out.println(total);
27
28
+}
29
30
+```
0 commit comments