Unable to find the mistake

Revision en2, by ankitsinha3005, 2017-11-29 09:28:14

Hi codeforces community, I'm new to codeforces and also a beginner in competitive coding.In the previous contest, i tried to solved this question.Your text to link here... from Codeforces Round #449(Div2). It is failing in test case 50 .Help from community will be highly appreciated . My code is below. ~~~~~

Your code here...

~~~~~

include

include <bits/stdc++.h>

using namespace std;

int main() { int n,sum1=0,sum2=0; cin>>n; vector ar(n); for(int i=0;i<n;i++) { cin>>ar[i]; } sort(ar.begin(),ar.end()); reverse(ar.begin(),ar.end()); for(int j=0;j<n;j++) {

        if(sum2>=sum1)
        sum1=sum1+ar[j];
        else
        sum2=sum2+ar[j];
         }

  if(sum1>=sum2)
  cout<<sum1-sum2;
  else
  cout<<sum2-sum1;

return 0;

}

Tags codeforces round#448

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English ankitsinha3005 2017-11-29 09:28:14 5 Tiny change: 'y code is given below.\n~' -> 'y code is below.\n~'
en1 English ankitsinha3005 2017-11-29 09:27:26 958 Initial revision (published)