wrong ans in test 15 ..dont getting which case is missing of codeforces twins (160A).. link to questn http://codeforces.com/problemset/problem/160/A

codeforces twins(160a)

#include<bits/stdc++.h>
using namespace std;

int main()
{

int n,i,z,x,c;
cin>>n;

int a[n];
for(i=0;i<n;i++)
   cin>>a[i];

sort(a,a+n);
int s=0;

for(i=0;i<n;i++)
{
s=s+a[i];
}

s=(s/2)+1;
x=0;
c=0;

for(i=n-1;i>=0;i--)
{

 if(a[n-1]<=s)
 {
  x=x+a[i];

  if(x<=s)
  {
    c++;
    continue;

  }

  else if(((x-a[i])<s)&&(i==0))
  {
      c++;
      break;
  }

  else if(x>s&&i!=0)
     x=x-a[i];

 }

   else
    {
     x=a[i];
     c=1;
     break;
    }

}

cout<<c;


return 0;
}

 

manish_kumar
Manish Kumar Savita
manish_kumar

Please Log in to answer

Note: Your answer should not be too short. Please wait a few seconds for the editor to load



Please make sure the answer is not too short

No Answer to this question yet

Comments
monsijb (Monsij Biswal) 09:05, Mar 29

Hey there, Observe the output for the case: 3 6 2 4 Hope that helps!👍