P12733 Adjust

Background

> "It really helps that we can 'adjust' so easily."\ --Saki Ayase

Description

Yuta and Saki encountered $n$ problems, where the difficulty of the problems are $d_1,\dots,d_n$. They can solve the problems in any order. For the $i$-th problem they choose to solve, reducing the difficulty by $1$ will cost them $i$ seconds. Once the difficulty is reduced to $0$, the problem is considered solved, and they can move on to the next problem. If they're solving the $i$-th problem (that is, the difficulty isn't reduced to $0$ yet) but the ramaining time is less than $i$ seconds, they cannot continue solving the remaining problems, and the $i$-th problem is also considered unsolved. They want to know, if they have a total time of $t$ 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 $t$ and ask this question.

Input Format

The first line contains two integers, $n$ and $q$, representing the number of problems and the number of queries, respectively. The second line is consisted of $n$ integers representing $d_1,\dots,d_n$. The following $q$ lines, each line contains an integer representing the total time $t$ 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.

Explanation/Hint

#### Sample 1 Explanation If $t=10$, they can solve the problem with a difficulty of $7$ first, then solve the problem with a difficulty of $1$, it will consume $1\times7+2\times1=9$ seconds. It can be proven that they cannot solve three problems. If $t=16$, then solving the problems with difficulty values of $7$, $3$, and $1$ in sequence would consume $1\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. | $n\le$ | $q\le$ | $d_i\le$ | $t\le$ | Score | Depends on Subtask | | :-: | :-: | :-: | :-: | :-: | :-: | :-: | | $1$ | $10$ | $1$ | $10$ | $10^3$ | $13$ | | | $2$ | $10^3$ | $1$ | $10^3$ | $10^9$ | $24$ | $1$ | | $3$ | $10^3$ | $10^6$ | $10^3$ | $10^9$ | $16$ | $1,2$ | | $4$ | $10^6$ | $1$ | $10^3$ | $10^{16}$ | $16$ | $1,2$ | | $5$ | $10^6$ | $10^6$ | $10^3$ | $10^{16}$ | $31$ | $1,2,3,4$ | For all of the testdata, $1\le n,q\le10^6$, $1\le d_i\le10^3$, $0\le t\le10^{16}$.