Блог пользователя ankitsinha3005

Автор ankitsinha3005, история, 7 лет назад, По-английски

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;

}

  • Проголосовать: нравится
  • -11
  • Проголосовать: не нравится

»
7 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

The problem statement says that you need to divide the sequence into two continuous segments. So you need to find the answer without changing the initial ordering of the array (you can't sort it ).