-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathboj1715.java
More file actions
28 lines (22 loc) · 743 Bytes
/
boj1715.java
File metadata and controls
28 lines (22 loc) · 743 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.PriorityQueue;
public class boj1715 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
long N = Long.parseLong(br.readLine());
PriorityQueue<Long> pq = new PriorityQueue<>();
for (int i = 0; i < N; i++) {
pq.add(Long.parseLong(br.readLine()));
}
long ans = 0;
while (pq.size() > 1) {
long tmp1 = pq.poll();
long tmp2 = pq.poll();
ans += tmp1 + tmp2;
pq.add(tmp1 + tmp2);
}
System.out.println(ans);
}
}