-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfallingapart.java
31 lines (29 loc) · 1000 Bytes
/
fallingapart.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.util.*;
import java.io.*;
public class fallingapart {
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());
String[] input = in.readLine().split(" ");
ArrayList<Integer> nums = new ArrayList<Integer>();
for(int i = 0; i < n; i++) nums.add(Integer.parseInt(input[i]));
Collections.sort(nums);
Collections.reverse(nums);
boolean a = true;
int aSum = 0;
int bSum = 0;
for(int j = 0; j < nums.size(); j++) {
if(a) {
aSum += nums.get(j);
a = false;
}
else {
bSum += nums.get(j);
a = true;
}
}
out.println(aSum + " " + bSum);
out.close();
}
}