欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF2183B.Yet Another MEX Problem
Yet Another MEX Problem
You are given an array of length , and an integer . Let be the value of . You want to perform the following operation times:
- Let the current length of the sequence be . You need to find an interval of length such that $\operatorname{max}_{i=1}^{|a|-k+1} f(i, i+k-1) = f(l, r).$ In other words, you need to select a window of size such that among all windows of size , the window you selected has the maximum . If multiple exist, you may select any. Then, you must select any integer such that , and delete from . That is, your new sequence will be $[a_1, a_2, \ldots, a_{i-1}, a_{i+1}, a_{i+2}, \ldots, a_n]$.
For example, in the array with , the two possible pairs are and (since they each have , which is the maximum among all windows of size ). Therefore, you can remove any one of the indices in your next move.
After operations, you will have a sequence of length . Your objective is to maximize the of the remaining elements. Please output the maximum possible.
The minimum excluded (MEX) of a collection of integers is defined as the smallest non-negative integer which does not occur in the collection .
Input
Each test contains multiple test cases. The first line contains the number of test cases (). The description of the test cases follows.
The first line of each test case contains two positive integers and ().
The second line of each test case contains integers ().
It is guaranteed that the sum of over all test cases does not exceed .
Output
Output a single non-negative integer representing your answer.
Note
In the first test case, we can select the interval . Then, delete to obtain . The process terminates, and the of the remaining elements is .
In the third test case, we can perform the following operations:
- Select . This is allowed because the of all windows of size is , and the window has a of , which is the largest. Then, remove . The sequence is now .
- Select . Then, remove . The sequence is now .
- Select . Then, remove . The sequence is now . The process terminates, and the final is .
Samples
5
3 3
0 0 0
4 2
0 2 1 3
5 3
0 1 2 1 0
6 2
0 1 0 1 2 0
7 5
0 1 2 4 0 3 1
1
1
2
1
4
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |