fork download
  1. bool v[M+1];
  2.  
  3. int go(vector<int> a) {
  4. memset(v,0,sizeof(v));
  5. v[0] = 1;
  6. int sum = 0;
  7. for(int i=0; i<a.size(); i++) {
  8. sum+=a[i];
  9. }
  10. for(int i=0; i<a.size(); i++) {
  11. for(int j=sum/2; j>=a[i]; j--) {
  12. v[j]|=v[j-a[i]];
  13. }
  14. }
  15. for(int i=sum/2; i>=0; i--) {
  16. if(v[i]) return sum-2*i;
  17. }
  18. return 0;
  19. }
  20.  
  21. int main() {
  22. ios_base::sync_with_stdio(0);
  23. int t;
  24. cin>>t;
  25. while(t-->0) {
  26. int n;
  27. cin>>n;
  28. vector<int> a;
  29. vector<int> b;
  30. for(int i=0; i<=n; i++) {
  31. if(i>0) {
  32. char c;
  33. cin>>c;
  34. }
  35. int x;
  36. cin>>x;
  37. if(i&1) a.push_back(x);
  38. else b.push_back(x);
  39. }
  40. if(n<3) {
  41. cout<<"NO"<<'\n';
  42. }
  43. else {
  44. cout<<go(a)+go(b)<<'\n';
  45. }
  46. }
  47. return 0;
  48. }
  49.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:1:8: error: 'M' was not declared in this scope
 bool v[M+1];
        ^
prog.cpp:3:8: error: 'vector' was not declared in this scope
 int go(vector<int> a) {
        ^
prog.cpp:3:15: error: expected primary-expression before 'int'
 int go(vector<int> a) {
               ^
prog.cpp:3:23: error: expected ',' or ';' before '{' token
 int go(vector<int> a) {
                       ^
stdout
Standard output is empty