fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4.  
  5. bool cmp(pair<int, int>& a,
  6. pair<int, int>& b)
  7. {
  8. return a.second < b.second;
  9. }
  10.  
  11. int main()
  12. {
  13. ios_base::sync_with_stdio(false);
  14. cin.tie(NULL);
  15. int t;
  16. cin>>t;
  17. while(t--)
  18. {
  19. int n,k;
  20. cin>>n>>k;
  21. int b[n+1];
  22. vector<pair<int,int>>a;
  23.  
  24. for(int i=0; i<n; i++)
  25. {
  26. int x;
  27. cin>>x;
  28. b[i]=x;
  29. a.push_back({i,x});
  30. }
  31. sort(a.begin(),a.end(),cmp);
  32. int f=1;
  33.  
  34. for(int i=n-k; i<k; i++)
  35. {
  36.  
  37. if(a[i].first!=i)
  38. {
  39. f=0;
  40. break;
  41. }
  42. }
  43. if(f==0)cout<<"NO"<<endl;
  44. else cout<<"YES"<<endl;
  45. }
  46. }
  47.  
Success #stdin #stdout 0s 5692KB
stdin
4
3 3
3 2 1
4 3
1 2 3 4
5 2
5 1 2 3 4
5 4
1 2 3 4 4
stdout
NO
YES
YES
YES