Ankit_132

A

Jun 18th, 2023
365
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.71 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define ll     long long
  6. #define _test   int _TEST; cin>>_TEST; while(_TEST--)
  7. #define ff     first
  8. #define ss     second
  9. #define pb     push_back
  10. #define ppb    pop_back
  11.  
  12. int main()
  13. {
  14.     _test
  15.     {
  16.         int n;
  17.         cin>>n;
  18.  
  19.         vector<int> a(n);
  20.         for(auto &e: a)     cin>>e;
  21.  
  22.         map<int, int> cnt;
  23.         for(auto e: a)
  24.             cnt[e]++;
  25.  
  26.         int f = 1;
  27.  
  28.         if(*max_element(a.begin(), a.end()) > n)        f = 0;
  29.  
  30.         for(int i=1; i<=n; i++)
  31.         {
  32.             if(cnt[i] > cnt[i-1])
  33.                 f = 0;
  34.         }
  35.  
  36.         if(f)       cout<<"YES\n";
  37.         else        cout<<"NO\n";
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment