fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. // your code goes here
  13. Scanner sc = new Scanner(System.in);
  14. int t =sc.nextInt();
  15. while(t-->0)
  16. {
  17. int n = sc.nextInt();
  18. int[] a = new int[n];
  19. int k = sc.nextInt();
  20. for(int i=0;i<n;i++)
  21. a[i]=sc.nextInt();
  22. System.out.println(answer(a,n,k));
  23. }
  24. }
  25. public static String answer(int a[],int n,int k)
  26. {
  27. if(a==null || n==0 || k<0)
  28. return "No";
  29. k=k%n;
  30. rev(a,0,n-1);
  31. rev(a,0,k-1);
  32. rev(a,k,n-1);
  33. return "Yes";
  34. }
  35. public static void rev(int[] a,int left,int right)
  36. {
  37. while(left<right)
  38. {
  39. int temp=a[left];
  40. a[left]=a[right];
  41. a[right]=temp;
  42. left++;
  43. right--;
  44. }
  45. }
  46. }
Success #stdin #stdout 0.12s 54460KB
stdin
6
5 3
4 3 3 2 3
3 100
7 2 1
5 5
6 1 1 1 1
1 1000000000
1
8 48
9 10 11 12 13 14 15 8
2 1
1 42
stdout
Yes
Yes
Yes
Yes
Yes
Yes