Advertisement
ivnikkk

Untitled

Jun 28th, 2022
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.74 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 == 4) {
  35.             bool ok = 1;
  36.             for (auto it : x) {
  37.                 if (x.find(-it) == x.end()) {
  38.                     ok = 0;
  39.                 }
  40.             }
  41.             if (ok) {
  42.                 cout << "YES\n";
  43.             }
  44.             else {
  45.                 cout << "NO\n";
  46.             }
  47.         }
  48.         else {
  49.             if (x.size() == 2) {
  50.                 bool ok = 1;
  51.                 for (auto it : x) {
  52.                     if (x.find(-it) == x.end()) {
  53.                         ok = 0;
  54.                     }
  55.                 }
  56.                 if (ok) {
  57.                     cout << "YES\n";
  58.                 }
  59.                 else {
  60.                     cout << "NO\n";
  61.                 }
  62.             }
  63.             else if (x.size() <=1) {
  64.                 cout << "YES\n";
  65.             }
  66.             else {
  67.                 cout << "NO\n";
  68.             }
  69.         }
  70.  
  71.     }
  72. }
  73.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement