#P12733. 磨合

    ID: 11569 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 5 上传者: 标签>数学贪心二分2025洛谷原创排序前缀和洛谷月赛

磨合

Description

Yuta and Saki encountered nn problems, where the difficulty of the problems are d1,,dnd_1,\dots,d_n.

They can solve the problems in any order. For the ii-th problem they choose to solve, reducing the difficulty by 11 will cost them ii seconds. Once the difficulty is reduced to 00, the problem is considered solved, and they can move on to the next problem.

If they're solving the ii-th problem (that is, the difficulty isn't reduced to 00 yet) but the ramaining time is less than ii seconds, they cannot continue solving the remaining problems, and the ii-th problem is also considered unsolved.

They want to know, if they have a total time of tt seconds, what is the maximum number of problems they can solve. Since they may face many different scenarios, they will repeatedly change the possible values of tt and ask this question.

Input Format

The first line contains two integers, nn and qq, representing the number of problems and the number of queries, respectively.

The second line is consisted of nn integers representing d1,,dnd_1,\dots,d_n.

The following qq lines, each line contains an integer representing the total time tt for the query.

Output Format

For each query, output a single integer on a line indicating the maximum number of problems that can be solved.

3 2
1 7 3
10
16

2
3

10 3
923 243 389 974 100 485 296 377 61 552
2403
5819
0

5
6
0

Hint

Sample 1 Explanation

If t=10t=10, they can solve the problem with a difficulty of 77 first, then solve the problem with a difficulty of 11, it will consume 1×7+2×1=91\times7+2\times1=9 seconds. It can be proven that they cannot solve three problems.

If t=16t=16, then solving the problems with difficulty values of 77, 33, and 11 in sequence would consume 1×7+2×3+3×1=161\times7+2\times3+3\times1=16 seconds.

Constraints

This problem enables subtask scoring and subtask dependence, with the constraints and scores for each subtask as follows.

Subtask No. nn\le qq\le did_i\le tt\le Score Depends on Subtask
11 1010 11 1010 10310^3 1313
22 10310^3 10310^3 10910^9 2424 11
33 10610^6 1616 1,21,2
44 10610^6 11 101610^{16}
55 10610^6 3131 1,2,3,41,2,3,4

For all of the testdata, 1n,q1061\le n,q\le10^6, 1di1031\le d_i\le10^3, 0t10160\le t\le10^{16}.