Advertisement
ivnikkk

Untitled

Jun 28th, 2022
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.30 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.     ll t;
  19.     cin >> t;
  20.     while (t--) {
  21.         ll n;
  22.         cin >> n;
  23.         vector<ll> a(n);
  24.         set<ll> x;
  25.         ll sum = 0;
  26.         for (ll i = 0; i < n; i++) {
  27.             cin >> a[i];
  28.             sum += a[i];
  29.             x.insert(a[i]);
  30.         }
  31.         if (n <= 10) {
  32.             bool ok = 1;
  33.             for (ll i = 0; i < n; i++) {
  34.                 for (ll j = i + 1; j < n; j++) {
  35.                     for (ll b = j + 1; b < n; b++) {
  36.                         if (x.find(a[i] + a[j] + a[b]) == x.end()) {
  37.                             ok = 0;
  38.                         }
  39.                         if (!ok)break;
  40.                     }
  41.                     if (!ok)break;
  42.  
  43.                 }
  44.                 if (!ok)break;
  45.             }
  46.             if (ok) {
  47.                 cout << "YES\n";
  48.             }
  49.             else {
  50.                 cout << "NO\n";
  51.             }
  52.         }
  53.         else {
  54.             if (x.size() == 3) {
  55.                 bool ok = 1;
  56.                 for (auto it : x) {
  57.                     if (x.find(-it) == x.end()) {
  58.                         ok = 0;
  59.                     }
  60.                 }
  61.                 if (x.find(0) == x.end())ok = 0;
  62.                 if (ok) {
  63.                     cout << "YES\n";
  64.                 }
  65.                 else {
  66.                     cout << "NO\n";
  67.                 }
  68.             }
  69.             else if(x.size() == 2) {
  70.                 bool ok = 1;
  71.                 if (x.find(0) == x.end())ok = 0;
  72.                 if (ok) {
  73.                     cout << "YES\n";
  74.                 }
  75.                 else {
  76.                     cout << "NO\n";
  77.                 }
  78.             }
  79.             else if (x.size() == 1) {
  80.                 cout << "YES\n";
  81.             }
  82.             else {
  83.                 cout << "NO\n";
  84.             }
  85.         }
  86.        
  87.     }
  88. }
  89.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement