欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1895A.Treasure Chest
Treasure Chest
Monocarp has found a treasure map. The map represents the treasure location as an OX axis. Monocarp is at , the treasure chest is at , the key to the chest is at .
Obviously, Monocarp wants to open the chest. He can perform the following actions:
- go to the left or to the right (spending second);
- pick the key or the chest up if he is in the same point as that object (spending seconds);
- put the chest down in his current point (spending seconds);
- open the chest if he's in the same point as the chest and has picked the key up (spending seconds).
Monocarp can carry the chest, but the chest is pretty heavy. He knows that he can carry it for at most seconds in total (putting it down and picking it back up doesn't reset his stamina).
What's the smallest time required for Monocarp to open the chest?
Input
The first line contains a single integer () — the number of testcases.
The only line of each testcase contains three integers and (; ; ) — the initial point of the chest, the point where the key is located, and the maximum time Monocarp can carry the chest for.
Output
For each testcase, print a single integer — the smallest time required for Monocarp to open the chest.
Note
In the first testcase, Monocarp can open the chest in seconds with the following sequence of moves:
- go times to the right ( seconds);
- pick up the chest ( seconds);
- go times to the right ( seconds);
- pick up the key ( seconds);
- put the chest down ( seconds);
- open the chest ( seconds).
He only carries the chest for seconds, which he has the stamina for.
In the second testcase, Monocarp can pick up the key on his way to the chest.
In the third testcase, Monocarp can't use the strategy from the first testcase because he would have to carry the chest for seconds, while he only has the stamina for seconds. Thus, he carries the chest to , puts it down, moves to the right to pick up the key and returns left to open the chest.
Samples
3
5 7 2
10 5 0
5 8 2
7
10
9
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |