欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1697A.Parkway Walk
Parkway Walk
You are walking through a parkway near your house. The parkway has benches in a row numbered from to from left to right. The distance between the bench and is meters.
Initially, you have units of energy. To walk meter of distance, you spend unit of your energy. You can't walk if you have no energy. Also, you can restore your energy by sitting on benches (and this is the only way to restore the energy). When you are sitting, you can restore any integer amount of energy you want (if you sit longer, you restore more energy). Note that the amount of your energy can exceed .
Your task is to find the minimum amount of energy you have to restore (by sitting on benches) to reach the bench from the bench (and end your walk).
You have to answer independent test cases.
Input
The first line of the input contains one integer () — the number of test cases. Then test cases follow.
The first line of the test case contains two integers and (; ).
The second line of the test case contains integers (), where is the distance between benches and .
Output
For each test case, print one integer — the minimum amount of energy you have to restore (by sitting on benches) to reach the bench from the bench (and end your walk) in the corresponding test case.
Note
In the first test case of the example, you can walk to the bench , spending unit of energy, then restore units of energy on the second bench, walk to the bench , spending units of energy, restore unit of energy and go to the bench .
In the third test case of the example, you have enough energy to just go to the bench without sitting at all.
Samples
3
3 1
1 2 1
4 5
3 3 5 2
5 16
1 2 3 4 5
3
8
0
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |