CF BUDDY
← Problems·

1873E · Building an Aquarium

1100 · binary search, sortings

Problem: 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 h1h \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.

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

The first line of each test case contains two positive integers nn and xx (1n21051 \leq n \leq 2 \cdot 10^5; 1x1091 \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 (1ai1091 \leq a_i \leq 10^9) — the heights of the coral.

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

Output Format: For each test case, output a single positive integer hh (h1h \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.

Note: 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.

Sample Cases

Case 1

Input

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

Output

4
4
2
335
1000000001

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback