All submissions for this problem are available.
Your teacher is very evil and gives you a lot of homework. In fact, the homework she gives you takes so much time that you get barely anytime to sleep. Today, she gave an extra-long homework: The teacher has given you a list A of N distinct integers, Q queries and an integer M. Each query will have two integers, i and R. You have to find j, such that a[j] is the ith smallest element for which a[j]%M = R. .
InputThe first line of each test case contains three integer N, Q and M denoting the number of elements in the array, number of queries and the modulus respectively The second line contains N space-separated integers A1, A2, ..., AN denoting the elements in the array. The next Q contains two integers: i and R.
OutputFor each query output one integer, j(1-indexed), which is the index such that a[j] is the ith smallest element for which a[j]%M = R. If it doesn't exist then print -1
Input: 8 5 4 1 5 7 3 9 11 0 4 1 1 2 1 3 1 1 3 5 3 Output: 1 2 5 4 -1
Example case 1. For the first query the answer is 1 because a is 1, which is the smallest element in the array with remainder 1.
|Time Limit:||1 - 2 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP 4.3.2, CPP 6.3, CPP14, JAVA, PYTH, PYTH 3.5|
Fetching successful submissions
If you are still having problems, see a sample solution here.