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 n pupils, the height of the i-th pupil in line is ai.
The line is comfortable, if for each i from 1 to n−1, the following condition holds: ai⋅2≥ai+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 ki, answer the question: what is the maximum height max(a1,a2,…,an) that can be achieved if the pupils eat at most ki pizzas.
有一天,“T世代”的老师们决定对学生们进行纪律教育,于是将他们排成一列,并让他们依次进行计算。总共有 n 名学生,队列中第 i 个学生的身高为 ai。
若对每个从 1 到 n−1 的 i,均满足条件 ai⋅2≥ai+1,则称该队列为舒适的。初始时,该队列是舒适的。
老师们不喜欢队列中的最大身高过小,因此打算给学生们披萨吃。已知每名学生每吃一个披萨,其身高就增加 1。每个披萨只能由一名学生食用,但每名学生可以吃任意多个披萨。重要的是:所有学生吃完披萨后,队列仍必须保持舒适。
老师们共有 q 种备选方案,表示他们将订购的披萨总数。对每种方案 ki,请回答如下问题:若学生们总共最多吃掉 ki 个披萨,那么所能达到的最大身高 max(a1,a2,…,an) 是多少?
输入格式
Each test contains multiple test cases. The first line contains a single integer t (1≤t≤104) — 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≤n,q≤5⋅104) — 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 a1,a2,…,an (1≤ai≤109) — 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 ki (1≤ki≤109) — 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⋅104.
It is guaranteed that the sum of the values of q across all sets of input data does not exceed 5⋅104.
每个测试包含多个测试用例。第一行包含一个整数 t(1≤t≤104),表示测试用例的数量。随后是各测试用例的描述。
每个测试用例的第一行包含两个整数 n 和 q(1≤n,q≤5⋅104),分别表示学生人数以及教师可能订购的披萨数量的选项个数。
每个测试用例的第二行包含 n 个整数 a1,a2,…,an(1≤ai≤109),表示各位学生的身高。题目保证初始队列是“舒适的”。
接下来的 q 行(每个测试用例对应 q 行)每行包含一个整数 ki(1≤ki≤109),表示学生可食用的披萨数量的新上限。
保证所有测试用例中 n 的总和不超过 5⋅104。
保证所有测试用例中 q 的总和不超过 5⋅104。
输出格式
For each test case, for each limit for how many pizzas the pupils can eat, output the maximum value max(a1,a2,…,an) that can be achieved while ensuring that the line is comfortable.
对于每个测试用例,针对学生可食用披萨数量的每个限制,输出在保证队列舒适的前提下所能达到的最大值 max(a1,a2,…,an)。
输入输出样例
输入#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 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⋅2≥26), and the maximum element in it is 26.
在第一组输入数据的第一个查询中,你可以先给第一位学生分发 3 个披萨,再给第二位学生分发 6 个披萨,使得最终数组为 [13,26](该数组是舒适的,因为 13⋅2≥26),其最大元素为 26。
输入解题思路,AI测评打分。不知道怎么写?