欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1730A.Planets
Planets
One day, Vogons wanted to build a new hyperspace highway through a distant system with planets. The -th planet is on the orbit , there could be multiple planets on the same orbit. It's a pity that all the planets are on the way and need to be destructed.
Vogons have two machines to do that.
- The first machine in one operation can destroy any planet at cost of Triganic Pu.
- The second machine in one operation can destroy all planets on a single orbit in this system at the cost of Triganic Pus.
Vogons can use each machine as many times as they want.
Vogons are very greedy, so they want to destroy all planets with minimum amount of money spent. Can you help them to know the minimum cost of this project?
Input
The first line contains a single integer () — the number of test cases. Then the test cases follow.
Each test case consists of two lines.
The first line contains two integers and () — the number of planets and the cost of the second machine usage.
The second line contains integers (), where is the orbit of the -th planet.
Output
For each test case print a single integer — the minimum cost of destroying all planets.
Note
In the first test case, the cost of using both machines is the same, so you can always use the second one and destroy all planets in orbit , all planets in orbit , all planets in orbit , all planets in orbit .
In the second test case, it is advantageous to use the second machine for Triganic Pus to destroy all the planets in orbit , then destroy the remaining two planets using the first machine.
In the third test case, you can use the first machine twice or the second machine once.
In the fourth test case, it is advantageous to use the first machine twice.
Samples
4
10 1
2 1 4 5 2 4 5 5 1 2
5 2
3 2 1 2 2
2 2
1 1
2 2
1 2
4
4
2
2
1
1 100
1
1
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |