fork download
  1. #include <stdio.h>
  2. #include<iostream>
  3. #include<cstring>
  4. #include<algorithm>
  5. #include<vector>
  6. #define gc getchar_unlocked
  7.  
  8. using namespace std;
  9.  
  10.  
  11.  
  12. int main() {
  13. iostream::sync_with_stdio(0);
  14. int t;
  15. cin>>t;
  16. while(t--)
  17. {
  18. int n;
  19. cin>>n;
  20. long long int a[n];
  21. for(int i=0;i<n;i++)
  22. {
  23. cin>>a[i];
  24. }
  25. //sort(a,a+n);
  26. int f=0;
  27. for(int i=1;i<n;i++)
  28. {
  29. if(a[i]-a[i-1]>1 || a[i]-a[i-1]<-1) { cout<<"NO"<<endl;
  30. f=1;
  31. break;
  32. }
  33. }
  34. if(f!=1) cout<<"YES"<<endl;
  35. }
  36. return 0;
  37. }
Success #stdin #stdout 0s 3464KB
stdin
2
4
3 2 2 3 
2
1 5
stdout
YES
NO