-
Notifications
You must be signed in to change notification settings - Fork 3
/
shopaholic.java
34 lines (32 loc) · 1.05 KB
/
shopaholic.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
32
33
34
import java.io.*;
import java.util.*;
public class shopaholic {
public static void main(String[] args) throws Exception {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
int n = Integer.parseInt(in.readLine());
StringTokenizer st = new StringTokenizer(in.readLine());
ArrayList<Long> nums = new ArrayList<Long>();
for(int i = 0; i < n; i++) {
nums.add(Long.parseLong(st.nextToken()));
}
Collections.sort(nums);
long total = 0;
//out.println(nums);
for(int i = n - 3; i >= 0; i -= 3) {
total += nums.get(i);
}
/*if(n % 3 != 0) {
int mod = n % 3;
if(mod == 1) {
total += nums.get(n - 1);
}
else {
total += nums.get(n - 1);
total += nums.get(n - 2);
}
}*/
out.println(total);
out.close();
}
}