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 given 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;
}