Hello 2025
F
Formation
Codeforces
3300
原题
← E2G →
翻译中…

One day, the teachers of "T-generation" decided to instill discipline in the pupils, so they lined them up and made them calculate in order. There are a total of $n$ pupils, the height of the $i$-th pupil in line is $a_i$.

翻译中…

The line is comfortable, if for each $i$ from $1$ to $n - 1$, the following condition holds: $a_i \cdot 2 \ge a_{i + 1}$. Initially, the line is comfortable.

翻译中…

The teachers do not like that the maximum height in the line is too small, so they want to feed the pupils pizza. You know that when a pupil eats one pizza, their height increases by $1$. One pizza can only be eaten by only one pupil, but each pupil can eat an unlimited number of pizzas. It is important that after all the pupils have eaten their pizzas, the line is comfortable.

翻译中…

The teachers have $q$ options for how many pizzas they will order. For each option $k_i$, answer the question: what is the maximum height $\max(a_1, a_2, \ldots, a_n)$ that can be achieved if the pupils eat at most $k_i$ pizzas.

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of test cases. The description of the test cases follows.

翻译中…

The first line of each set of test case contains two integers $n$ and $q$ ($1 \le n, q \le 5 \cdot 10^4$) — the number of pupils and the number of options for how many pizzas the teachers will order.

翻译中…

The second line of each set of test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$) — the heights of the pupils.It is guaranteed that initially, the line is comfortable.

翻译中…

Each of the following $q$ lines of each set of input data contains one integer $k_i$ ($1 \le k_i \le 10^9$) — the next limit for how many pizzas the pupils can eat.

翻译中…

It is guaranteed that the sum of the values of $n$ across all sets of input data does not exceed $5 \cdot 10^4$.

翻译中…

It is guaranteed that the sum of the values of $q$ across all sets of input data does not exceed $5 \cdot 10^4$.

翻译中…

Output

翻译中…

For each test case, for each limit for how many pizzas the pupils can eat, output the maximum value $\max(a_1, a_2, \ldots, a_n)$ that can be achieved while ensuring that the line is comfortable.

翻译中…

Note

翻译中…

In the first query of the first set of input data, you can first give $3$ pizzas to the first pupil, and then give $6$ pizzas to the second pupil, making the final array $[13, 26]$ (the line is comfortable since $13 \cdot 2 \ge 26$), and the maximum element in it is $26$.

翻译中…

样例

Input #1
3
2 1
10 20
10
6 7
3 1 2 4 5 6
1
2
4
8
16
32
64
10 4
1 2 4 8 16 32 64 128 256 512
10
100
1000
10000
Output #1
26
7 8 10 12 19 35 67
513 560 1011 10001
InputCopy OutputCopy
题目信息
题号
2057F
所属比赛
时间限制
3 s
内存限制
512 MB
标签
二分
数据结构
动态规划
排序
双指针

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。