fork download
  1. #include <iostream>
  2. #include<bits/stdc++.h>
  3. using namespace std;
  4.  
  5. int main() {
  6. // your code goes here
  7. int t;
  8. cin>>t;
  9. while(t--){
  10. int n,k;
  11. cin>>n>>k;
  12. k=k%n;
  13. int s;
  14. s=n-k;
  15. vector<int>v(n);
  16. for(int i=0;i<n;i++){
  17. cin>>v[i];
  18. }
  19. reverse(v.begin(),v.begin()+s);
  20. reverse(v.begin()+s,v.end());
  21. reverse(v.begin(),v.end());
  22. for(int i=0;i<n;i++){
  23. cout<<v[i]<<" ";
  24. }
  25. cout<<"\n";
  26. }
  27. return 0;
  28. }
Success #stdin #stdout 0s 5284KB
stdin
3
5
2 
1 2 3 4 5
7
3
1 2 3 4 5 6 9 
6
8
1 2 3 4 5 6
stdout
4 5 1 2 3 
5 6 9 1 2 3 4 
5 6 1 2 3 4