fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long int
  4.  
  5. int main() {
  6. int t;
  7. cin>>t;
  8. while(t--){
  9. int n, k;
  10. cin>>n>>k;
  11. vector<int>v(n,0);
  12. bool sorted = true;
  13. for(int i=0;i<n;i++){
  14. int x;
  15. cin>>x;
  16. v[i]=x;
  17. if(i>=1 and v[i]<v[i-1]){
  18. sorted = false;
  19. }
  20. }
  21.  
  22. if(k>=2){
  23. cout<<"YES"<<endl;
  24. } else if(k==1 and sorted){
  25. cout<<"YES"<<endl;
  26. } else{
  27. cout<<"NO"<<endl;
  28. }
  29. }
  30. return 0;
  31. }
Success #stdin #stdout 0s 5276KB
stdin
5
3 2
1 2 3
3 1
9 9 9
4 4
6 4 2 1
4 3
10 3 830 14
2 1
3 1
stdout
YES
YES
YES
YES
NO