CF1873E.Building an Aquarium

普及-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You love fish, that's why you have decided to build an aquarium. You have a piece of coral made of nn columns, the ii-th of which is aia_i units tall. Afterwards, you will build a tank around the coral as follows:

  • Pick an integer h≥1h \geq 1 — the height of the tank. Build walls of height hh on either side of the tank.
  • Then, fill the tank up with water so that the height of each column is hh, unless the coral is taller than hh; then no water should be added to this column.

For example, with a=[3,1,2,4,6,2,5]a=[3,1,2,4,6,2,5] and a height of h=4h=4, you will end up using a total of w=8w=8 units of water, as shown.

You can use at most xx units of water to fill up the tank, but you want to build the biggest tank possible. What is the largest value of hh you can select?

你非常喜欢鱼,因此决定建造一个水族箱。你有一块由 nn 列珊瑚组成的珊瑚礁,其中第 ii 列的高度为 aia_i 个单位。之后,你将围绕这块珊瑚建造一个水箱,具体步骤如下:

  • 选择一个整数 h≥1h \geq 1 —— 即水箱的高度。在水箱左右两侧各建造高度为 hh 的墙壁。
  • 然后向水箱中注水,使得每列的总高度(珊瑚高度加水高度)达到 hh;但如果某列珊瑚本身已高于 hh,则该列不加水。

例如,当 a=[3,1,2,4,6,2,5]a=[3,1,2,4,6,2,5] 且水箱高度 h=4h=4 时,总共需要 w=8w=8 单位的水,如下图所示。

你最多只能使用 xx 单位的水来注满水箱,但你希望建造尽可能大的水箱。你能选择的最大 hh 值是多少?

输入格式

The first line contains a single integer tt (1≤t≤1041 \leq t \leq 10^4) — the number of test cases.

The first line of each test case contains two positive integers nn and xx (1≤n≤2⋅1051 \leq n \leq 2 \cdot 10^5; 1≤x≤1091 \leq x \leq 10^9) — the number of columns of the coral and the maximum amount of water you can use.

The second line of each test case contains nn space-separated integers aia_i (1≤ai≤1091 \leq a_i \leq 10^9) — the heights of the coral.

The sum of nn over all test cases doesn't exceed 2⋅1052 \cdot 10^5.

第一行包含一个整数 tt(1≤t≤1041 \leq t \leq 10^4)—— 测试用例的数量。

每个测试用例的第一行包含两个正整数 nn 和 xx(1≤n≤2⋅1051 \leq n \leq 2 \cdot 10^5;1≤x≤1091 \leq x \leq 10^9)—— 珊瑚的列数以及你最多可使用的水量。

每个测试用例的第二行包含 nn 个以空格分隔的整数 aia_i(1≤ai≤1091 \leq a_i \leq 10^9)—— 各列珊瑚的高度。

所有测试用例中 nn 的总和不超过 2⋅1052 \cdot 10^5。

输出格式

For each test case, output a single positive integer hh (h≥1h \geq 1) — the maximum height the tank can have, so you need at most xx units of water to fill up the tank.

We have a proof that under these constraints, such a value of hh always exists.

对于每个测试用例,输出一个正整数 hh(h≥1h \geq 1)——即水箱可能达到的最大高度,使得填满该水箱所需水量至多为 xx 个单位。

在本题约束条件下,可以证明这样的 hh 值一定存在。

输入输出样例

  • 输入#1

    5
    7 9
    3 1 2 4 6 2 5
    3 10
    1 1 1
    4 1
    1 4 3 4
    6 1984
    2 6 5 9 1 8
    1 1000000000
    1

    输出#1

    4
    4
    2
    335
    1000000001

说明/提示

The first test case is pictured in the statement. With h=4h=4 we need 88 units of water, but if hh is increased to 55 we need 1313 units of water, which is more than x=9x=9. So h=4h=4 is optimal.

In the second test case, we can pick h=4h=4 and add 33 units to each column, using a total of 99 units of water. It can be shown that this is optimal.

In the third test case, we can pick h=2h=2 and use all of our water, so it is optimal.

第一个测试用例如题面图示所示。当 h=4h=4 时,我们需要 88 单位的水;但若将 hh 增加至 55,则需要 1313 单位的水,超过了 x=9x=9。因此 h=4h=4 是最优的。

在第二个测试用例中,我们可以选择 h=4h=4,并向每一列添加 33 单位的水,总共使用 99 单位的水。可以证明这是最优解。

在第三个测试用例中,我们可以选择 h=2h=2 并恰好用完所有水,因此这是最优的。

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

首页