#abc334d. D - Reindeer and Sleigh

D - Reindeer and Sleigh

Score : 400400 points

问题描述

NN 辆雪橇,编号为 1,2,,N1,2,\ldots, N

ii 辆雪橇需要 RiR_i 只驯鹿来拉动。

另外,每只驯鹿最多只能拉动一辆雪橇。更准确地说,要拉动 mm 辆雪橇 i1,i2,,imi_1, i_2, \ldots, i_m,需要 k=1mRik\sum_{k=1}^{m} R_{i_k} 只驯鹿。

求解以下形式的 QQ 个查询的答案:

  • 给定一个整数 XX,确定在有 XX 只驯鹿的情况下,最多可以拉动多少辆雪橇。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

There are NN sleighs numbered 1,2,,N1,2,\ldots, N.

RiR_i reindeer are required to pull sleigh ii.

Additionally, each reindeer can pull at most one sleigh. More precisely, k=1mRik\sum_{k=1}^{m} R_{i_k} reindeer are required to pull mm sleighs i1,i2,,imi_1, i_2, \ldots, i_m.

Find the answer to QQ queries of the following form:

  • You are given an integer XX. Determine the maximum number of sleighs that can be pulled when there are XX reindeer.

Constraints

  • 1N,Q2×1051 \leq N, Q \leq 2 \times 10^5
  • 1Ri1091 \leq R_i \leq 10^9
  • 1X2×10141 \leq X \leq 2 \times 10^{14}
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

NN QQ

R1R_1 R2R_2 \ldots RNR_N

query1\text{query}_1

query2\text{query}_2

\vdots

queryQ\text{query}_Q

Each query is given in the following format:

XX

Output

Print QQ lines.

The ii-th line should contain the answer to the ii-th query.

Sample Input 1

4 3
5 3 11 8
16
7
1000

Sample Output 1

3
1
4

When there are 1616 reindeer, sleighs 1,2,41,2,4 can be pulled.

It is impossible to pull four sleighs with 1616 reindeer, so the answer to query 11 is 33.

Sample Input 2

6 6
1 2 3 4 5 6
1
2
3
4
5
6

Sample Output 2

1
1
2
2
2
3

Sample Input 3

2 2
1000000000 1000000000
200000000000000
1

Sample Output 3

2
0

update @ 2024/3/10 01:21:25

}