欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1873E.Building an Aquarium
Building an Aquarium
You love fish, that's why you have decided to build an aquarium. You have a piece of coral made of columns, the -th of which is units tall. Afterwards, you will build a tank around the coral as follows:
- Pick an integer — the height of the tank. Build walls of height on either side of the tank.
- Then, fill the tank up with water so that the height of each column is , unless the coral is taller than ; then no water should be added to this column.
For example, with and a height of , you will end up using a total of units of water, as shown.
You can use at most units of water to fill up the tank, but you want to build the biggest tank possible. What is the largest value of you can select?
Input
The first line contains a single integer () — the number of test cases.
The first line of each test case contains two positive integers and (; ) — the number of columns of the coral and the maximum amount of water you can use.
The second line of each test case contains space-separated integers () — the heights of the coral.
The sum of over all test cases doesn't exceed .
Output
For each test case, output a single positive integer () — the maximum height the tank can have, so you need at most units of water to fill up the tank.
We have a proof that under these constraints, such a value of always exists.
Note
The first test case is pictured in the statement. With we need units of water, but if is increased to we need units of water, which is more than . So is optimal.
In the second test case, we can pick and add units to each column, using a total of units of water. It can be shown that this is optimal.
In the third test case, we can pick and use all of our water, so it is optimal.
Samples
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
4
4
2
335
1000000001
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |