欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF2036B.Startup
Startup
Arseniy came up with another business plan — to sell soda from a vending machine! For this, he purchased a machine with shelves, as well as bottles, where the -th bottle is characterized by the brand index and the cost .
You can place any number of bottles on each shelf, but all bottles on the same shelf must be of the same brand.
Arseniy knows that all the bottles he puts on the shelves of the machine will be sold. Therefore, he asked you to calculate the maximum amount he can earn.
Input
The first line contains one integer () — the number of test cases.
The first line of each test case contains two integers and (), where is the number of shelves in the machine, and is the number of bottles available to Arseniy.
The next lines contain two integers and () — the brand and cost of the -th bottle.
It is also guaranteed that the sum of across all test cases does not exceed and that the sum of across all test cases also does not exceed .
Output
For each test case, output one integer — the maximum amount that Arseniy can earn.
Note
In the first test case, Arseniy has shelves in the vending machine. He can place, for example, two bottles of the brand on the first shelf and a bottle of the brand on the second shelf. Then the total cost of the bottles would be .
In the second test case, he has only one shelf. It is not difficult to show that the optimal option is to place a bottle of the brand on it. Then the total cost will be .
In the third test case, he has as many as shelves, so he can place all available bottles with a total cost of .
Samples
4
3 3
2 6
2 7
1 15
1 3
2 6
2 7
1 15
6 2
1 7
2 5
190000 1
1 1000
28
15
12
1000
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |