Answers for "twins problem codeforses div 2A"

0

twins problem codeforses div 2A

#include<bits/stdc++.h>
using namespace std;
#define N 1001
int a[N];
int n;
int sum;
int it;
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)cin>>a[i];
    sort(a+1,a+n+1);
    for(int i=1;i<=n;i++) sum+=a[i];
    it=sum/2+1;
    int hh=0;
    int cnt=0;
    for(int i=n;i>=1;i--)
    {
        cnt++;
        hh+=a[i];
        if(hh>=it) 
        {
            cout<<cnt<<endl;break;
        }
    }
}
Posted by: Guest on September-07-2021
0

twins problem codeforses div 2A

#include<bits/stdc++.h>
using namespace std;
#define N 1001
int a[N];
int n;
int sum;
int it;
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)cin>>a[i];
    sort(a+1,a+n+1);
    for(int i=1;i<=n;i++) sum+=a[i];
    it=sum/2+1;
    int hh=0;
    int cnt=0;
    for(int i=n;i>=1;i--)
    {
        cnt++;
        hh+=a[i];
        if(hh>=it) 
        {
            cout<<cnt<<endl;break;
        }
    }
}1234567891011121314151617181920212223242526
Posted by: Guest on September-07-2021

Browse Popular Code Answers by Language