Advertisement
arif334

Triplet Solution

May 6th, 2024
642
0
17 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.62 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. string solve()
  5. {
  6.     int n, a;
  7.     map<int, int> m;
  8.  
  9.     cin >> n;
  10.     while(n--) {
  11.         cin >> a;
  12.         m[a]++;
  13.     }
  14.  
  15.     if(m.count(0) >= 3) return "YES";
  16.  
  17.     for(auto [k, v]: m) {
  18.         if(v >= 2 && m.count(-(k+k)) >= 1) return "YES";
  19.     }
  20.  
  21.     for(auto [k1, v1]: m) {
  22.         for(auto [k2, v2]: m) {
  23.             if(k1 != k2 && m.count(-(k1+k2)) >= 1) return "YES";
  24.         }
  25.     }
  26.  
  27.     return "NO";
  28. }
  29.  
  30. int main()
  31. {
  32.     #ifndef ONLINE_JUDGE
  33.         freopen("in.txt", "r", stdin);
  34.     #endif
  35.  
  36.     cout << solve() << "\n";
  37.  
  38.     return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement