#SGM0000068. Số nhỏ thứ k (K-th Number)
Số nhỏ thứ k (K-th Number)
K-th Number
Source: POJ
Version: Phuoc Hung OJ Extended
Problem
The array contains distinct integers. Query asks for the -th smallest value in .
Input
The first line contains , the second line contains distinct integers, and each of the next lines contains .
Output
Print the -th smallest value for each query.
Subtasks
Subtask 1 (20%)
- , number of queries .
- All other conditions are the same as Subtask 3.
Subtask 2 (30%)
- , number of queries .
- All other conditions are the same as Subtask 3.
Subtask 3 (50%)
- and all values are distinct
Example
Input
7 3
1 5 2 6 3 7 4
2 5 3
4 4 1
1 7 3
Output
5
6
3
Explanation
The segment [5,2,6,3] becomes [2,3,5,6], so its third smallest value is .