A. Twins

Source: Internet
Author: User

Time limit per test

2 seconds

Memory limit per test

256 megabytes

Input

Standard Input

Output

Standard output

Imagine that you have a twin brother or sister. having another person that looks exactly like you seems very unusual. it's hard to say if having something of an alter ego is good or bad. and if you do have a twin, then you very well know what it's like.

Now let's imagine a typical morning in your family. you haven't woken up yet, and mom is already going to work. she has been so hasty that she has nearly forgotten to leave the two of her darling children some money to buy lunches in the school cafeteria. she
Fished in the purse and found some number of coins, or to be exact,NCoins of arbitrary valuesA1, bytes,A2, middle..., middle ,...,AN.
But as Mom was running out of time, she didn't split the coins for you two. So she scribbled a note asking you to split the money equally.

As you woke up, you found Mom's coins and read her note. "But why split the money equally? "-You thought. After all, your twin is sleeping and he won't know anything. So you decided to act like that: pick for yourself some subset of coins so that the sum
Values of your coins is strictly larger than the sum of values of the remaining coins that your twin will have. However, you correctly thought that if you take too encode coins, the twin will suspect
The deception. so, you 've decided to stick to the following strategy to avoid suspicions: You take the minimum number of coins, whose sum of values is strictly more than the sum of values of
Remaining coins. On this basis, determine what minimum number of coins you need to take to divide them in the described manner.

Input

The first line contains integerN(1 digit ≤ DigitNLimit ≤ limit 100 )-
The number of coins. The second line contains a sequenceNIntegersA1,A2,
...,AN(1 digit ≤ DigitAILimit ≤0000100)
-The coins 'values. All numbers are separated with spaces.

Output

In the single line print the single number-the minimum needed number of coins.

Sample test (s) Input
23 3
Output
2
Input
32 1 2
Output
2
Note

In the first sample you will have to take 2 coins (you and your twin have sums equal to 6, then 0 correspondingly ).
If you take 1 coin, you get sums 3, consume 3. If you take 0 coins,
You get sums 0, listen 6. Those variants do not satisfy you as your sum shocould be strictly more that your twins 'sum.

In the second sample one coin isn' t enough for us, too. You can pick coins with values 1, limit 2 or 2, limit 2.
In any case, the minimum number of coins equals 2.

Solution Description: This is to sort the data first and then use greed. Fortunately, the data volume here is not very large, so you can bubble up.

#include <iostream>#include<cstdio>#include<cstring>#include<cmath>using namespace std;int main(){int n,i,j;int sum;int a[101];int temp;int count;int suma;sum=0;count=0;suma=0;scanf("%d",&n);for(i=0;i<n;i++){scanf("%d",&a[i]);sum+=a[i];}for(i=0;i<n;i++){for(j=i+1;j<n;j++){if(a[i]<a[j]){temp=a[i];a[i]=a[j];a[j]=temp;}}}for(i=0;i<n;i++){suma+=a[i];count++;if(2*suma>sum){printf("%d\n",count);break;}}return 0;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.