CF1730A.Planets
入门
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
One day, Vogons wanted to build a new hyperspace highway through a distant system with n planets. The i-th planet is on the orbit ai, 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 1 Triganic Pu.
- The second machine in one operation can destroy all planets on a single orbit in this system at the cost of c 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?
一天,沃贡人想要在一颗遥远的星系中修建一条新的超空间高速公路,该星系共有 n 颗行星。第 i 颗行星位于轨道 ai 上,同一轨道上可能有多个行星。遗憾的是,所有行星都位于高速公路的规划路线上,因此必须全部摧毁。
沃贡人拥有两台机器来完成这项任务:
- 第一台机器每次操作可摧毁任意一颗行星,花费为 1 特里加尼克普(Triganic Pu);
- 第二台机器每次操作可摧毁该星系中某一条轨道上的所有行星,花费为 c 特里加尼克普。
沃贡人可以无限次使用任一机器。
沃贡人非常贪婪,因此希望以最少的花费摧毁所有行星。你能帮他们计算出该项目的最小总花费吗?
输入格式
The first line contains a single integer t (1≤t≤100) — the number of test cases. Then the test cases follow.
Each test case consists of two lines.
The first line contains two integers n and c (1≤n,c≤100) — the number of planets and the cost of the second machine usage.
The second line contains n integers a1,a2,…,an (1≤ai≤100), where ai is the orbit of the i-th planet.
第一行包含一个整数 t(1≤t≤100),表示测试用例的数量。随后是各测试用例。
每个测试用例由两行组成。
第一行包含两个整数 n 和 c(1≤n,c≤100),分别表示行星的数量和第二台机器的使用成本。
第二行包含 n 个整数 a1,a2,…,an(1≤ai≤100),其中 ai 表示第 i 颗行星的轨道半径。
输出格式
For each test case print a single integer — the minimum cost of destroying all planets.
对于每个测试用例,输出一个整数——摧毁所有行星的最小代价。
输入输出样例
输入#1
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
输出#1
4 4 2 2
输入#2
1 1 100 1
输出#2
1
说明/提示
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 1, all planets in orbit 2, all planets in orbit 4, all planets in orbit 5.
In the second test case, it is advantageous to use the second machine for 2 Triganic Pus to destroy all the planets in orbit 2, 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.
在第一个测试用例中,使用两台机器的成本相同,因此你可以始终使用第二台机器,摧毁轨道 1、轨道 2、轨道 4 和轨道 5 上的所有行星。
在第二个测试用例中,使用第二台机器花费 2 特里加尼克普斯(Triganic Pus)来摧毁轨道 2 上的所有行星更为有利,然后使用第一台机器摧毁剩余的两颗行星。
在第三个测试用例中,你可以使用第一台机器两次,或者使用第二台机器一次。
在第四个测试用例中,使用第一台机器两次更为有利。
输入解题思路,AI测评打分。不知道怎么写?