Skip to content

Commit 4e47aed

Browse files
authored
[20250702] BOJ / G4 / 카드 정렬하기 / 설진영
1 parent 31121c0 commit 4e47aed

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)