Advertisement
Guest User

Untitled

a guest
Apr 5th, 2020
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.74 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. void process(){
  6.     int n;
  7.     cin >> n;
  8.     vector<int> a(n);
  9.     for(int i=0;i<n;i++) cin >> a[i];
  10.  
  11.     if (n == 1){
  12.         cout << "NO\n";
  13.         return;
  14.     }
  15.     sort(a.begin(),a.end());
  16.    
  17.     int l = 0;
  18.     int r = n-1;
  19.     int suml = a[l], sumr = a[r];
  20.     while(l<r){
  21.        
  22.         if (suml >= sumr){
  23.             r--;
  24.             sumr += a[r];
  25.         }
  26.         if (l == r) break;
  27.         if (suml < sumr){
  28.             l++;
  29.             suml += a[l];
  30.         }
  31.         if (l == r) break;
  32.     }  
  33.     if (suml == sumr){
  34.         cout << "YES\n";
  35.     }else cout << "NO\n";
  36. }
  37.  
  38. int main(){
  39.  
  40.     int T;
  41.     cin >> T;
  42.     while (T--) process();
  43.  
  44.     return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement