CF2057F.Formation

NOI/NOI+/CTSC

通过率:0%

时间限制:3.00s

内存限制:512MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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 nn pupils, the height of the ii-th pupil in line is aia_i.

The line is comfortable, if for each ii from 11 to n−1n - 1, the following condition holds: ai⋅2≥ai+1a_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 11. 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 qq options for how many pizzas they will order. For each option kik_i, answer the question: what is the maximum height max⁡(a1,a2,…,an)\max(a_1, a_2, \ldots, a_n) that can be achieved if the pupils eat at most kik_i pizzas.

有一天,“T世代”的老师们决定对学生们进行纪律教育,于是将他们排成一列,并让他们依次进行计算。总共有 nn 名学生,队列中第 ii 个学生的身高为 aia_i。

若对每个从 11 到 n−1n - 1 的 ii,均满足条件 ai⋅2≥ai+1a_i \cdot 2 \ge a_{i + 1},则称该队列为舒适的。初始时,该队列是舒适的。

老师们不喜欢队列中的最大身高过小,因此打算给学生们披萨吃。已知每名学生每吃一个披萨,其身高就增加 11。每个披萨只能由一名学生食用,但每名学生可以吃任意多个披萨。重要的是:所有学生吃完披萨后,队列仍必须保持舒适。

老师们共有 qq 种备选方案,表示他们将订购的披萨总数。对每种方案 kik_i,请回答如下问题:若学生们总共最多吃掉 kik_i 个披萨,那么所能达到的最大身高 max⁡(a1,a2,…,an)\max(a_1, a_2, \ldots, a_n) 是多少?

输入格式

Each test contains multiple test cases. The first line contains a single integer tt (1≤t≤1041 \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 nn and qq (1≤n,q≤5⋅1041 \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 nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (1≤ai≤1091 \le a_i \le 10^9) — the heights of the pupils.It is guaranteed that initially, the line is comfortable.

Each of the following qq lines of each set of input data contains one integer kik_i (1≤ki≤1091 \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 nn across all sets of input data does not exceed 5⋅1045 \cdot 10^4.

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

每个测试包含多个测试用例。第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4),表示测试用例的数量。随后是各测试用例的描述。

每个测试用例的第一行包含两个整数 nn 和 qq(1≤n,q≤5⋅1041 \le n, q \le 5 \cdot 10^4),分别表示学生人数以及教师可能订购的披萨数量的选项个数。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(1≤ai≤1091 \le a_i \le 10^9),表示各位学生的身高。题目保证初始队列是“舒适的”。

接下来的 qq 行(每个测试用例对应 qq 行)每行包含一个整数 kik_i(1≤ki≤1091 \le k_i \le 10^9),表示学生可食用的披萨数量的新上限。

保证所有测试用例中 nn 的总和不超过 5⋅1045 \cdot 10^4。

保证所有测试用例中 qq 的总和不超过 5⋅1045 \cdot 10^4。

输出格式

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

对于每个测试用例,针对学生可食用披萨数量的每个限制,输出在保证队列舒适的前提下所能达到的最大值 max⁡(a1,a2,…,an)\max(a_1, a_2, \ldots, a_n)。

输入输出样例

  • 输入#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

    输出#1

    26
    7 8 10 12 19 35 67
    513 560 1011 10001

说明/提示

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

在第一组输入数据的第一个查询中,你可以先给第一位学生分发 33 个披萨,再给第二位学生分发 66 个披萨,使得最终数组为 [13,26][13, 26](该数组是舒适的,因为 13⋅2≥2613 \cdot 2 \ge 26),其最大元素为 2626。

输入解题思路,AI测评打分。不知道怎么写?

首页