Created
August 21, 2016 23:46
-
-
Save SahilKadam/2d588f2bcdf3a7aaaa6db016fc83cd70 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 dup[] = new int[n]; | |
int arr_q[] = new int[q]; | |
for(int n_i=0; n_i<n; n_i++){ | |
arr[n_i] = s.nextInt(); | |
dup[n_i] = arr[n_i]; | |
} | |
k = k%n; | |
int temp; | |
for(int i=0;i<n;i++){ | |
temp = (i+n-k)%n; | |
arr[i]=dup[temp]; | |
} | |
for(int q_i=0; q_i<q; q_i++){ | |
arr_q[q_i] = s.nextInt(); | |
if(arr_q[q_i] < n) | |
System.out.print(arr[arr_q[q_i]] + "\n"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment