fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main(){
  5. int t,n; cin >> t;
  6. while(t--){
  7. cin >> n;
  8. vector<int> s(n);
  9. bool psble = true;
  10. for(int i=0;i<n;i++) cin >> s[i];
  11. for(int i=1;i<n;i++){
  12. if(s[i-1] > s[i] && s[i-1] - s[i] > 1){
  13. psble = false;
  14. break;
  15. }else if(s[i] < s[i-1]) swap(s[i],s[i-1]);
  16. }
  17. //for(auto i : s) cout << i << " ";
  18. psble ? cout << "YES\n" : cout << "NO\n";
  19. }
  20. return 0;
  21. }
  22.  
Success #stdin #stdout 0.01s 5276KB
stdin
2
4
2 1 3 4
4
4 3 2 1 
stdout
YES
NO