P20180 [CodeChef] KTHMAX
普及
题目描述

You are given an array A of size N. Let us list down all the subarrays of the given array. There will be a total of N * (N + 1) / 2 subarrays of the given array. Let us sort each of the subarrays in descending order of the numbers in it.

Now you want to sort these subarrays in descending order. You can compare two subarrays B, C, as follows.

compare(B, C):
Append N - |B| zeros at the end of the array B.
Append N - |C| zeros at the end of the array C.
for i = 1 to N:
if B[i] < C[i]:
return B is less than C
if B[i] > C[i]:
return B is greater than C
return B and C are equal.

You are given M queries asking for the maximum element in the pth subarray (1-based indexing).

-----Input-----
The first line of input contains T, the number of test cases.
The first line of each test case contains two space separated integers N and M, denoting the array size and the number of queries respectively.
The next line contains N space-separated integers denoting the array elements.

Each of the next M lines contains a single integer - p.

-----Output-----
Output a single integer corresponding to the maximum element in the pth subarray.

-----Constraints-----
- 1 ≤ Ai ≤ 109
- 1 ≤ p ≤ N+1C2

-----Subtasks-----Subtask #1 (20 points):
- 1 ≤ T ≤ 20
- 1 ≤ N ≤ 200
- 1 ≤ M ≤ 104
Subtask #2 (30 points):
- 1 ≤ T ≤ 20
- 1 ≤ N ≤ 3000
- 1 ≤ M ≤ 104
Subtask #3 (50 points):
- 1 ≤ T ≤ 5
- 1 ≤ N ≤ 105
- 1 ≤ M ≤ 105

-----Example-----
Input:1
4 2
3 1 2 4
1
5

Output:4
3

输入格式

见题面

输出格式

见题面

样例输入
['1', '4 2', '3 1 2 4', '1', '5']
样例输出
['4', '3']