Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- void process(){
- int n;
- cin >> n;
- vector<int> a(n);
- for(int i=0;i<n;i++) cin >> a[i];
- if (n == 1){
- cout << "NO\n";
- return;
- }
- sort(a.begin(),a.end());
- int l = 0;
- int r = n-1;
- int suml = a[l], sumr = a[r];
- while(l<r){
- if (suml >= sumr){
- r--;
- sumr += a[r];
- }
- if (l == r) break;
- if (suml < sumr){
- l++;
- suml += a[l];
- }
- if (l == r) break;
- }
- if (suml == sumr){
- cout << "YES\n";
- }else cout << "NO\n";
- }
- int main(){
- int T;
- cin >> T;
- while (T--) process();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement