fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main(){
  5. int t;
  6. cin >> t;
  7. while(t--){
  8. vector<int> a;
  9. int s;
  10. cin >> s;
  11. while(s--){
  12. int x;
  13. cin >> x;
  14. a.push_back(x);
  15. }
  16. sort(a.begin(),a.end(),greater<int>());
  17. /*for(int j=0;j<a.size();++j){
  18. cout << a[j] << " ";
  19. }
  20. cout << endl;*/
  21. int cnt = 0;
  22. for(int j=a.size()-1;j>0;--j){
  23. if(a[j-1] - a[j] <= 1){
  24. cnt++;
  25. }
  26. }
  27.  
  28. /*for(int j=0;j<a.size();++j){
  29. cout << a[j] << " ";
  30. }*/
  31.  
  32. //cout << endl << a.size() << " " << cnt << endl;
  33. if(a.size()-cnt == 1)
  34. cout << "YES\n";
  35. else
  36. cout << "NO\n";
  37. }
  38. return 0;
  39. }
Success #stdin #stdout 0.01s 5276KB
stdin
5
3
1 2 2
4
5 5 5 5
3
1 2 4
4
1 3 4 4
1
100
stdout
YES
YES
NO
NO
YES