There is a group of $n$ + $m$ friends; $n$ of them are in a singing competition and the other $m$ are voting for their friends. A participant in the singing competition qualifies to the next stage if they receive at least $k$ votes.
Each of the $m$ friends has a fixed number of votes, and none of them can vote for the same participant twice. Unfortunately, the current number of votes for each participant has just been leaked. By that time, none of the $m$ friends had voted for any of their $n$ friends yet.
The friends decided to work together, and guarantee that they will vote in a way that maximizes the number of their friends that will qualify to the next stage. However, the minimum number of votes $k$ required to qualify has not been announced publicly.
Your job is to write a program for them that finds for $q$ different values of $k$, the maximum number of friends that can qualify to the next stage?
The first line of input contains two integers $n$ and $m$ ($1 \le n, m \le 2\times10^5$), the number of friends competing, and the number of friends voting.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 2\times10^5$), where $a_i$ is the leaked number of votes the $i^{th}$ participating friend has already received.
The third line contains $m$ integers $b_1, b_2, \dots, b_m$ ($1 \le b_i \le n$), where $b_i$ is the number of votes the $i^{th}$ voting friend can make.
The fourth line contains a single integer $q$ ($1 \le q \leq 500$), the number of values you have to find the answer for.
The last line contains $q$ different values of $k$ ($1 \le k \le 2\times10^5$), where $k$ is the minimum number of votes a participant needs to receive to qualify to the next stage.
For each given value of $k$, print the maximum number of participants who can qualify if their friends voted for them in the best possible way. Print all answers on a single line.
Input | Output |
---|---|
5 3 8 4 6 8 7 4 3 5 3 10 7 11 Copy
|
3 5 2 Copy
|