欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1430B.Barrels
Barrels
You have barrels lined up in a row, numbered from left to right from one. Initially, the -th barrel contains liters of water.
You can pour water from one barrel to another. In one act of pouring, you can choose two different barrels and (the -th barrel shouldn't be empty) and pour any possible amount of water from barrel to barrel (possibly, all water). You may assume that barrels have infinite capacity, so you can pour any amount of water in each of them.
Calculate the maximum possible difference between the maximum and the minimum amount of water in the barrels, if you can pour water at most times.
Some examples:
- if you have four barrels, each containing liters of water, and , you may pour liters from the second barrel into the fourth, so the amounts of water in the barrels are , and the difference between the maximum and the minimum is ;
- if all barrels are empty, you can't make any operation, so the difference between the maximum and the minimum amount is still .
Input
The first line contains one integer () — the number of test cases.
The first line of each test case contains two integers and () — the number of barrels and the number of pourings you can make.
The second line contains integers (), where is the initial amount of water the -th barrel has.
It's guaranteed that the total sum of over test cases doesn't exceed .
Output
For each test case, print the maximum possible difference between the maximum and the minimum amount of water in the barrels, if you can pour water at most times.
Samples
2
4 1
5 5 5 5
3 2
0 0 0
10
0
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |