欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF2013B.Battle for Survive
Battle for Survive
Eralim, being the mafia boss, manages a group of fighters. Fighter has a rating of .
Eralim arranges a tournament of battles, in each of which two not yet eliminated fighters and () are chosen, and as a result of the battle, fighter is eliminated from the tournament, and the rating of fighter is reduced by the rating of fighter . That is, is decreased by . Note that fighter 's rating can become negative. The fighters indexes do not change.
Eralim wants to know what maximum rating the last remaining fighter can preserve if he chooses the battles optimally.
Input
Each test contains multiple test cases. The first line contains the number of test cases (). The description of the test cases follows.
The first line of each test case contains a single integer () — the number of fighters.
The second line of each test case contains integers () — the ratings of the fighters.
The sum of over all testcases does not exceed .
Output
For each testcase, output a single integer — the maximum rating that the last remaining fighter can preserve.
Note
In the first example, you can arrange a fight between fighters with indices and , where the fighter with index will win. The rating of the last fighter, that is, the fighter with index , will be .
In the second example, you can first conduct a fight between fighters with indices and , where the fighter with index will win, and then conduct a fight between fighters with indices and , where the fighter with index will win.
The rating of the fighter with index after the first fight will be . The rating of the fighter with index after the second fight will be .
Samples
5
2
2 1
3
2 2 8
4
1 2 4 3
5
1 2 3 4 5
5
3 2 4 5 4
-1
8
2
7
8
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |