-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathCF160ATwins.java
More file actions
42 lines (34 loc) · 955 Bytes
/
CF160ATwins.java
File metadata and controls
42 lines (34 loc) · 955 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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.stream.IntStream;
/**
* See <a href="http://codeforces.com/problemset/problem/160/A">Twins</a>
*
* @author Brian Yeicol Restrepo Tangarife
*/
public class CF160ATwins {
static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
static PrintWriter out = new PrintWriter(System.out);
public static void main(String[] args) throws IOException {
Integer n =Integer.parseInt(in.readLine());
int[] coins = Arrays.stream(in.readLine().split("\\s"))
.mapToInt(Integer::parseInt)
.sorted()
.toArray();
int totalAmount = IntStream.of(coins).sum();
int amount = 0;
int totalCoins = 0;
while(n-- > 0) {
amount += coins[n];
totalCoins++;
if (amount > totalAmount / 2) {
break;
}
}
out.print(totalCoins);
out.close();
}
}