#b. XHXMMMlOPUkTFF#**$?
XHXMMMlOPUkTFF#**$?
该比赛已结束,您无法在比赛模式下递交该题目。您可以点击“在题库中打开”以普通模式查看和递交本题。
Statement
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.
Format
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.
Sample
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
ShanghaiTech ACM 炸鱼杯
- 状态
- 已结束
- 规则
- OI
- 题目
- 46
- 开始于
- 2024-12-10 23:00
- 结束于
- 2024-12-15 13:00
- 持续时间
- 110 小时
- 主持人
- 参赛人数
- 112