You are given some coins. You have to take some coins from the given coins such that the sum of the coins you took have a value strictly larger than the sum of the rest of the coins. However, you have to take minimum number of coins while satisfying this condition
9. You are given some coins. You have to take some coins from the given coins such that the sum of the coins
you took have a value strictly larger than the sum of the rest of the coins. However, you have to take
minimum number of coins while satisfying this condition
Input
In the first line, you are given n (n<=100), the number of integer numbers. In the next line, you will be given n
integers, separated by spaces.
Output
Output one number, the minimum number of coins you need to take to have a larger sum than the sum of the
coins you did not take.
Input Output
2
3 3
2
3
2 1 2
2
6
4 2 1 2 1 1
2
In the first sample you will have to take 2 coins. If you take 1 coin, you get sum 3, 3. If you take 0 coins, you get
sums 0, 6. Those variants do not satisfy you as your sum should be strictly more than the other sum.
In the second sample one coin isn't enough for you, too. You can pick coins with values 1, 2 or 2, 2. In any case,
the minimum number of coins equals 2.
In third sample, if you take the coin with value 4 and 2. You have a sum of 6, Rest of them will have a sum of 5.
Answer is 2. And you can’t to this in less than 2 coin.
Step by step
Solved in 3 steps with 4 images