Advertisement
PROFESSOR_AIH

C. 3SUM Closure

Feb 2nd, 2023
620
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.74 KB | None | 0 0
  1. int main()
  2. {
  3.     ios_base::sync_with_stdio(false);
  4.     int t;
  5.     cin>>t;
  6.     for(int k=1; k<=t; k++)
  7.     {
  8.         int n;
  9.         cin>>n;
  10.         vector<int>arr(n);
  11.         map<int,int>mp;
  12.         for(int i=0; i<n; i++)
  13.         {
  14.             cin>>arr[i];
  15.             mp[arr[i]]=1;
  16.         }
  17.         bool flag=false;
  18.         for(int i=0; i<n; i++)
  19.         {
  20.             for(int j=i+1; j<n-1; j++)
  21.             {
  22.                 if(mp[arr[i]+arr[j]+arr[j+1]]!=1)
  23.                 {
  24.                     flag=true;
  25.                     break;
  26.                 }
  27.             }
  28.             if(flag)
  29.                 break;
  30.         }
  31.         if(flag)
  32.             cout<<"NO"<<endl;
  33.         else
  34.             cout<<"YES"<<endl;
  35.  
  36.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement