-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTwins.java
More file actions
42 lines (33 loc) · 867 Bytes
/
Twins.java
File metadata and controls
42 lines (33 loc) · 867 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.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
public class Twins
{
public static void main( String[] args )
{
Scanner scanner = new Scanner( System.in );
int n = scanner.nextInt();
int[] coins = new int[ n ];
int index = 0;
int sum = 0;
while( index < n )
{
int coin = scanner.nextInt();
coins[index++] = coin;
sum += coin;
}
Arrays.sort( coins );
int minCoins =0;
int minCoinsSum=0;
for( int i = coins.length-1; i >=0 ; i-- )
{
minCoins++;
minCoinsSum+=coins[i];
if(minCoinsSum>(sum/2))
{
break;
}
}
System.out.println( minCoins );
}
}