欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF2004C.Splitting Items
Splitting Items
Alice and Bob have items they'd like to split between them, so they decided to play a game. All items have a cost, and the -th item costs . Players move in turns starting from Alice.
In each turn, the player chooses one of the remaining items and takes it. The game goes on until no items are left.
Let's say that is the total cost of items taken by Alice and is the total cost of Bob's items. The resulting score of the game then will be equal to .
Alice wants to maximize the score, while Bob wants to minimize it. Both Alice and Bob will play optimally.
But the game will take place tomorrow, so today Bob can modify the costs a little. He can increase the costs of several (possibly none or all) items by an integer value (possibly, by the same value or by different values for each item). However, the total increase must be less than or equal to . Otherwise, Alice may suspect something. Note that Bob can't decrease costs, only increase.
What is the minimum possible score Bob can achieve?
Input
The first line contains a single integer () — the number of test cases. Then cases follow.
The first line of each test case contains two integers and (; ) — the number of items and the maximum total increase Bob can make.
The second line of each test case contains integers () — the initial costs of the items.
It's guaranteed that the sum of over all test cases doesn't exceed .
Output
For each test case, print a single integer — the minimum possible score after Bob increases the costs of several (possibly none or all) items.
Note
In the first test case, Bob can increase by , making costs equal to . Tomorrow, Alice will take and Bob will take . The total score will be equal to , and it's the minimum possible.
In the second test case, Bob can't change costs. So the score will be equal to , since Alice will take , Bob will take , and Alice — .
In the third test case, Bob, for example, can increase by , by , and by . The total change is equal to and costs will be equal to . Obviously, the score will be equal to .
In the fourth test case, Bob can increase by , making costs equal to . The score will be equal to .
Samples
4
2 5
1 10
3 0
10 15 12
4 6
3 1 2 4
2 4
6 9
4
13
0
0
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |