-
Notifications
You must be signed in to change notification settings - Fork 0
/
ATM.java
31 lines (24 loc) · 825 Bytes
/
ATM.java
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
29
30
31
import java.io.*;
import java.util.Arrays;
import java.util.StringTokenizer;
public class ATM {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int num = Integer.parseInt(br.readLine());
int sum = 0;
int[] arr = new int[num];
StringTokenizer st = new StringTokenizer(br.readLine(), " ");
for(int i = 0; i < num; i++) {
arr[i] = Integer.parseInt(st.nextToken());
}
Arrays.sort(arr);
for(int i = 0; i < num; i++) {
sum += arr[i] * (num - i);
}
bw.write(sum + "\n");
bw.flush();
bw.close();
br.close();
}
}