A15271 | Planets
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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 $a_i$ , 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?
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?
输入格式
The first line contains a single integer $t$ ( $1 \le t \le 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 \le n, c \le 100$ ) — the number of planets and the cost of the second machine usage.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ( $1 \le a_i \le 100$ ), where $a_i$ is the orbit of the $i$ -th planet.
Each test case consists of two lines.
The first line contains two integers $n$ and $c$ ( $1 \le n, c \le 100$ ) — the number of planets and the cost of the second machine usage.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ( $1 \le a_i \le 100$ ), where $a_i$ is the orbit of the $i$ -th planet.
输出格式
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.
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.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted