1104 : Tian Ji's Horse Race Again
| 比对Compare | token 相同即通过。中间的空格、制表符、换行可多可少。Matching tokens pass. Extra spaces, tabs, or newlines between them are ignored. |
|---|---|
| 不同则错Differs | token 个数或内容不同即错误。23 与 2 3、02 与 2、2.0 与 2 均视为不同。A different token count or value is wrong. 23 vs 2 3, 02 vs 2, and 2.0 vs 2 all differ. |
| 输入Input | 标准输入,格式见题面。Standard input; format as in the statement. |
| 输出Output | 标准输出。Standard output. |
题目描述Description
Last time, the king of the country Qi lost to Tian Ji in a horse race as Tian using a little trick. Today, the king invites Tian to play another horse race. The king and Tian both have n horses, and no two horses have the same speed. They will play n rounds in this match. The horses on each side must appear in descending order of speed, and each of the horses must be used in one round. The horse with a faster speed will win in a single round. Since Tian’s horses are not so nice as the king’s, the king allows Tian to exchange some horses with him.
If Tian can exchange at most k horses with the king, what is the maximum number of rounds that Tian can win?
输入格式Input
There will be at most 200 test cases. Each case begins with two integers n, m(1 ≤ m ≤ n ≤ 105), the number of horses on each side and the number of queries. The next line contains n positive integers, denoting the speeds of king’s horses in descending order. Then the following line contains n positive integers, denoting the speeds of Tian’s horses in descending order. The speed of each horse will not exceed 106, and no two horses have the same speed. The queries are defined by the following m lines, and each line contains one integer k(0 ≤ k < n). The size of the whole input file does not exceed 10MB.
输出格式Output
For each query, print the maximum number of rounds that Tian can win, when he can exchange at most k horses with the king.
样例Sample
出题Author
Staginner