Skip to content

Commit f10d319

Browse files
authored
Merge pull request #876 from AlgorithmWithGod/zinnnn37
[20250912] BOJ / G4 / 카드 정렬하기 / 김민진
2 parents 80cb0e2 + 8ba8565 commit f10d319

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
```java
2+
import java.io.*;
3+
import java.util.PriorityQueue;
4+
import java.util.Queue;
5+
6+
public class BJ_1715_카드_정렬하기 {
7+
8+
private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
9+
private static final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
10+
11+
private static int N;
12+
private static int ans;
13+
14+
private static Queue<Integer> pq;
15+
16+
public static void main(String[] args) throws IOException {
17+
init();
18+
sol();
19+
}
20+
21+
private static void init() throws IOException {
22+
pq = new PriorityQueue<>();
23+
ans = 0;
24+
25+
N = Integer.parseInt(br.readLine());
26+
while (N-- > 0) {
27+
int n = Integer.parseInt(br.readLine());
28+
pq.offer(n);
29+
}
30+
}
31+
32+
private static void sol() throws IOException {
33+
while (pq.size() > 1) {
34+
int a = pq.poll();
35+
int b = pq.poll();
36+
37+
pq.add(a + b);
38+
ans += a + b;
39+
}
40+
bw.write(ans + "");
41+
bw.flush();
42+
bw.close();
43+
br.close();
44+
}
45+
46+
}
47+
```

0 commit comments

Comments
 (0)