Created
August 21, 2016 23:24
-
-
Save SahilKadam/dc6f0acae528bf1c647908a1d630e5f2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.*; | |
import java.util.*; | |
import java.text.*; | |
import java.math.*; | |
import java.util.regex.*; | |
public class Solution { | |
public static void main(String[] args) { | |
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */ | |
Scanner s = new Scanner(System.in); | |
int n = s.nextInt(); | |
int k = s.nextInt(); | |
int q = s.nextInt(); | |
int arr[] = new int[n]; | |
int arr_q[] = new int[q]; | |
for(int n_i=0; n_i<n; n_i++) | |
arr[n_i] = s.nextInt(); | |
for(int q_i=0; q_i<q; q_i++) | |
arr_q[q_i] = s.nextInt(); | |
for(int i=0; i<(k%n); i++){ | |
int temp = arr[n-1]; | |
for(int j=n-1; j>0; j--) | |
arr[j] = arr[j-1]; | |
arr[0] = temp; | |
} | |
for(int a=0; a<q; a++) | |
if(arr_q[a] < n) | |
System.out.print(arr[arr_q[a]] + "\n"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment