Papers
题号:NC237410
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
64bit IO Format: %lld

题目描述


Alan has a large number of papers to write. Being a good student majoring in Computer Science, his brain is powerful enough to write at most  papers at the same time.

At any time, Alan can start to write a new paper if the number of papers he has started but not yet finished is less than . Once he starts to write a new paper in the -th hour, he will use the next  consecutive hours to complete it. In other words, he will finish this new paper in the -th hour, where  is the number of papers that Alan has started and has not yet finished (doesn't include the new paper) and  is a non-decreasing array.

For example, if Alan needs to write  papers and . Define an array  as the time when the paper will be completed for the  papers he is writing currently. One possible strategy can be described as follows:

  1. At first, Alan begins to write  papers, so that .

  2. At the end of the first hour, Alan begins to write the third paper, so that .

  3. At the end of the second hour, Alan finishes his first paper, so  becomes . At the same time, he begins to write his fourth paper, so .

  4. At the end of the fourth hour, Alan finishes his second paper, so  becomes . At the same time, he begins to write his fifth paper, so .

  5. At the end of the sixth hour, Alan finishes his third paper, so  becomes .

  6. At the end of the seventh hour, Alan finishes his fourth paper, so  becomes .

  7. At the end of the ninth hour, Alan finishes his fifth paper, so  becomes .

So, it takes  hours for Alan to finish all his  papers if he takes such action.

Doesn't know how many papers he needs to write, Alan will ask you  times and each time he will give you a positive integer , which is the number of papers. To finish his homework as fast as possible and then go to play the computer games, Alan wants to know the minimum time he needs. You must tell him how many hours he needs to complete all his papers if his strategy is optimal.

输入描述:

The first line of the input contains a single integer  , denoting the number of papers that Alice can write at the same time.

The second line contains  integers  , where  denotes the number of hours it will take Alice to finish this paper if he has  started and not finished papers currently. It is guaranteed that .

The third line contains a single integer  , denoting the number of queries.

For the next  lines, each line contains a single integer  , indicating the number of papers he needs to finish.

输出描述:

For each query, output a single integer, indicating the minimum number of hours that Alice needs if he wants to finish all his  papers.
示例1

输入

复制
3
2 4 5
2
3
5

输出

复制
5
9

说明

In the first example:

For , Alan can write all his  papers together at the beginning, and these  papers will be completed in the second, fourth, and fifth hour, respectively. So, that will take him  hours to finish three papers.

For , the situation is the same as mentioned in the statement.


示例2

输入

复制
4
1 1 4 5
2
1
4

输出

复制
1
2

说明

In the second example:

For , Alice will finish his first and second papers in the first hour, and finish his third and fourth papers in the second hour.