欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF2057B.Gorilla and the Exam
Gorilla and the Exam
Due to a shortage of teachers in the senior class of the "T-generation", it was decided to have a huge male gorilla conduct exams for the students. However, it is not that simple; to prove his competence, he needs to solve the following problem.
For an array , we define the function as the smallest number of the following operations required to make the array empty:
- take two integers and , such that , and let be the ; then
- remove all such that and from the array, the deleted elements are removed, the indices are renumerated.
You are given an array of length and an integer . No more than times, you can choose any index () and any integer , and replace with .
Help the gorilla to determine the smallest value of that can be achieved after such replacements.
Input
Each test contains multiple test cases. The first line contains a single integer () — the number of test cases. The description of the test cases follows.
The first line of each set of input data contains two integers and (, ) — the length of the array and the maximum number of changes, respectively.
The second line of each set of input data contains integers () — the array itself.
It is guaranteed that the sum of the values of across all sets of input data does not exceed .
Output
For each set of input data, output a single integer on a separate line — the smallest possible value of .
Note
In the first set of input data, , since the array consists of a single number, and thus it can be removed in one operation.
In the second set of input data, you can change the second number to , resulting in the array , where , since you can take the entire array as a subarray, the minimum on it is , so we will remove all the s from the array, and the array will become empty.
Samples
6
1 0
48843
3 1
2 3 2
5 3
1 2 3 4 5
7 0
4 7 1 3 2 4 1
11 4
3 2 1 4 4 3 4 2 1 3 3
5 5
1 2 3 4 5
1
1
2
5
2
1
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |