fork download
  1. #include <bits/stdc++.h>
  2. #define int long long
  3. using namespace std;
  4.  
  5. void solve() {
  6. int n;
  7. cin >> n;
  8. vector<int> v(n+1);
  9. for(int i=1;i<=n;i++)cin>>v[i];
  10. sort(v.begin(),v.end());
  11. vector<int> a(n+1,0),b(n+1,0);
  12. if(v[1]!=v[2]){
  13. cout<<"NO"<<endl;
  14. return;
  15. }
  16. int k=v[1]+1;
  17. for(int i=3;i<=n-1;i+=2){
  18. int p=v[i],q=v[i+1];
  19. if(p>k || q>k){
  20. cout<<"NO"<<endl;
  21. return;
  22. }
  23. while(p!=k){
  24. p++;
  25. }
  26. while(q!=k){
  27. q++;
  28. }
  29. k++;
  30. }
  31. cout<<"YES"<<endl;
  32.  
  33. }
  34.  
  35. signed main() {
  36. int t;
  37. cin >> t;
  38. while (t--) {
  39. solve();
  40. }
  41. return 0;
  42. }
  43.  
Success #stdin #stdout 0.01s 5288KB
stdin
9
2
1 1
2
2 1
4
1 1 4 4
4
3 4 3 3
4
2 3 4 4
6
3 3 4 5 3 3
6
2 2 2 4 4 4
8
1 1 1 1 1 1 1 4
10
9 9 9 10 10 10 10 10 10 10
stdout
YES
NO
NO
YES
NO
YES
NO
YES
YES