Advertisement
ivnikkk

Untitled

Jun 28th, 2022
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.04 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #define debug(tl) cerr<<#tl<<' '<<tl<<'\n';
  3. #include "bits/stdc++.h"
  4. using namespace std;
  5. #define all(d) d.begin(), d.end()
  6. typedef long long ll;
  7. typedef pair<ll, ll> pll;
  8. typedef pair<int, int> pii;
  9. typedef long double ld;
  10. signed main() {
  11. #ifdef _DEBUG
  12.     freopen("input.txt", "r", stdin);
  13.     freopen("output.txt", "w", stdout);
  14. #endif
  15.     ios_base::sync_with_stdio(false);
  16.     cin.tie(nullptr);
  17.     cout.tie(nullptr);
  18.     srand(time(NULL));
  19.     ll t;
  20.     cin >> t;
  21.     while (t--) {
  22.         ll n;
  23.         cin >> n;
  24.         vector<ll> a(n);
  25.         multiset<ll> x;
  26.         ll sum = 0;
  27.         ll cnt0 = 0;
  28.         for (ll i = 0; i < n; i++) {
  29.             cin >> a[i];
  30.             sum += a[i];
  31.             cnt0 += a[i] == 0;
  32.             if(a[i] != 0)x.insert(a[i]);
  33.         }
  34.         if (n <= 10) {
  35.             bool ok = 1;
  36.             for (ll i = 0; i < n; i++) {
  37.                 for (ll j = i + 1; j < n; j++) {
  38.                     for (ll b = j + 1; b < n; b++) {
  39.                         if (x.find(a[i] + a[j] + a[b]) == x.end()) {
  40.                             ok = 0;
  41.                         }
  42.                         if (!ok)break;
  43.                     }
  44.                     if (!ok)break;
  45.  
  46.                 }
  47.                 if (!ok)break;
  48.             }
  49.             if (ok) {
  50.                 cout << "YES\n";
  51.             }
  52.             else {
  53.                 cout << "NO\n";
  54.             }
  55.         }
  56.         else {
  57.             if (x.size() == 2) {
  58.                 bool ok = 1;
  59.                 for (auto it : x) {
  60.                     if (x.find(-it) == x.end()) {
  61.                         ok = 0;
  62.                     }
  63.                 }
  64.                 if (ok) {
  65.                     cout << "YES\n";
  66.                 }
  67.                 else {
  68.                     cout << "NO\n";
  69.                 }
  70.             }
  71.             else if (x.size() == 1) {
  72.                 cout << "YES\n";
  73.             }
  74.             else {
  75.                 cout << "NO\n";
  76.             }
  77.         }
  78.  
  79.     }
  80. }
  81.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement