Skip to content

Commit f337d2b

Browse files
authored
Merge pull request #637 from AlgorithmWithGod/lkhyun
[20250809] / BOJ / G4 파일 합치기 3 / 이강현
2 parents 0e99db4 + 9f91032 commit f337d2b

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
```java
2+
import java.util.*;
3+
import java.io.*;
4+
5+
public class Main {
6+
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
7+
static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
8+
static StringTokenizer st;
9+
static int T;
10+
11+
public static void main(String[] args) throws Exception {
12+
T = Integer.parseInt(br.readLine());
13+
14+
for (int t = 0; t < T; t++) {
15+
PriorityQueue<Long> pq = new PriorityQueue<>();
16+
17+
int K = Integer.parseInt(br.readLine());
18+
st = new StringTokenizer(br.readLine());
19+
for (int i = 0; i < K; i++) {
20+
pq.offer(Long.parseLong(st.nextToken()));
21+
}
22+
long ans = 0;
23+
while(pq.size() != 1){
24+
long cur1 = pq.poll();
25+
long cur2 = pq.poll();
26+
ans += cur1+cur2;
27+
pq.offer(cur1+cur2);
28+
}
29+
bw.write(ans+"\n");
30+
}
31+
bw.close();
32+
}
33+
}
34+
```

0 commit comments

Comments
 (0)