CF2185C.Shifted MEX
入门
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given an array of n integers a1,a2,…,an. You are allowed to perform the following operation once.
- Select an integer x (which may be negative), and for each value i (1≤i≤n), set ai=ai+x.
For example, if a=[1,3,4,2], and you perform the operation with x=3, a is now equal to [4,6,7,5].
Output the maximum possible value of MEX(a)∗ after the operation is performed.
∗MEX(a) is defined as the smallest non-negative integer that is not present in the array. For example, MEX([1,2,0,5]) is 3, and MEX([1,2,4,9]) is 0.
给你一个包含 n 个整数的数组 a1,a2,…,an。你被允许执行以下操作恰好一次:
- 选择一个整数 x(可以为负数),并对每个下标 i(其中 1≤i≤n),令 ai=ai+x。
例如,若 a=[1,3,4,2],且你选取 x=3 执行该操作,则数组 a 将变为 [4,6,7,5]。
请输出执行该操作后 MEX(a)∗ 的最大可能值。
∗MEX(a) 定义为不在数组中出现的最小非负整数。例如,MEX([1,2,0,5])=3,而 MEX([1,2,4,9])=0。
输入格式
The first line of the input contains a single integer t (1≤t≤1000) — the number of test cases.
The first line of each test case contains a single integer n (1≤n≤3000) — the length of array a.
The second line contains n integers a1,a2,…,an (−109≤ai≤109) — the array a.
It is guaranteed that the sum of n over all test cases does not exceed 3000.
输入的第一行包含一个整数 t(1≤t≤1000),表示测试用例的数量。
每个测试用例的第一行包含一个整数 n(1≤n≤3000),表示数组 a 的长度。
第二行包含 n 个整数 a1,a2,…,an(−109≤ai≤109),即数组 a。
保证所有测试用例的 n 之和不超过 3000。
输出格式
For each test case, output the maximum possible value of MEX(a) after the operation has been performed.
对于每个测试用例,输出执行操作后 MEX(a) 的最大可能值。
输入输出样例
输入#1
6 1 4 5 0 1 1 2 3 2 1 1 4 4 2 3 6 5 2 4 1 0 -1 6 -1 1 2 3 5 6
输出#1
1 4 1 3 4 3
说明/提示
For the first test case, performing the operation with x=−4 makes a=[0], and MEX([0])=1.
For the second test case, the MEX is already 4, which is the highest possible, so we can perform the operation with x=0, which will not change the array.
对于第一个测试用例,执行 x=−4 的操作后,数组变为 a=[0],此时 MEX([0])=1。
对于第二个测试用例,当前 MEX 已为 4,这已是可能的最大值,因此我们可以执行 x=0 的操作,该操作不会改变数组。
输入解题思路,AI测评打分。不知道怎么写?