-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBOJ_16208.java
More file actions
28 lines (23 loc) · 798 Bytes
/
Copy pathBOJ_16208.java
File metadata and controls
28 lines (23 loc) · 798 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
// BOJ - 16208
// Problem Sheet - https://www.acmicpc.net/problem/16208
import java.util.*;
import java.io.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
int[] rods = Arrays.stream(br.readLine().split(" "))
.mapToInt(Integer::parseInt)
.toArray();
int totalLength = Arrays.stream(rods).sum();
Arrays.sort(rods);
long minPrice = 0;
for (int i=0 ; i<n-1 ; i++) {
totalLength -= rods[i];
minPrice += (long) rods[i] * totalLength;
}
System.out.println(minPrice);
br.close();
System.exit(0);
}
}