[Solution] Scuza Codeforces Solution | Solution Codeforces
Timur has a stairway with steps. The -th step is meters higher than its predecessor. The first step is meters higher than the ground, and the ground starts at meters.
Timur has questions, each denoted by an integer . For each question , you have to print the maxmimum possible height Timur can achieve by climbing the steps if his legs are of length . Timur can only climb the -th step if his legs are of length at least . In other words, for each step climbed.
Note that you should answer each question independently.
The first line contains a single integer () — the number of test cases.
The first line of each test case contains two integers () — the number of steps and the number of questions, respectively.
The second line of each test case contains integers () — the height of the steps.
The third line of each test case contains integers () — the numbers for each question.
It is guaranteed that the sum of does not exceed , and the sum of does not exceed .
For each test case, output a single line containing integers, the answer for each question.
Please note, that the answer for some questions won't fit into 32-bit integer type, so you should use at least 64-bit integer type in your programming language (like long long for C++).
Consider the first test case, pictured in the statement.
- If Timur's legs have length , then he can only climb stair , so the highest he can reach is meter.
- If Timur's legs have length or , then he can only climb stairs , , and , so the highest he can reach is meters.
- If Timur's legs have length or , then he can climb the whole staircase, so the highest he can reach is meters.
In the first question of the second test case, Timur has no legs, so he cannot go up even a single step. :(
No comments:
Post a Comment