CF2185C.Shifted MEX

入门

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given an array of nn integers a1,a2,…,ana_1, a_2, \ldots, a_n. You are allowed to perform the following operation once.

  • Select an integer xx (which may be negative), and for each value ii (1≤i≤n)(1 \leq i \leq n), set ai=ai+xa_i = a_i + x.

For example, if a=[1,3,4,2]a = [1, 3, 4, 2], and you perform the operation with x=3x = 3, aa is now equal to [4,6,7,5][4, 6, 7, 5].

Output the maximum possible value of MEX⁡(a)\operatorname{MEX}(a)∗^{\text{∗}} after the operation is performed.

∗^{\text{∗}}MEX⁡(a)\operatorname{MEX}(a) is defined as the smallest non-negative integer that is not present in the array. For example, MEX⁡([1,2,0,5])\operatorname{MEX}([1, 2, 0, 5]) is 33, and MEX⁡([1,2,4,9])\operatorname{MEX}([1, 2, 4, 9]) is 00.

给你一个包含 nn 个整数的数组 a1,a2,…,ana_1, a_2, \ldots, a_n。你被允许执行以下操作恰好一次:

  • 选择一个整数 xx(可以为负数),并对每个下标 ii(其中 1≤i≤n1 \leq i \leq n),令 ai=ai+xa_i = a_i + x。

例如,若 a=[1,3,4,2]a = [1, 3, 4, 2],且你选取 x=3x = 3 执行该操作,则数组 aa 将变为 [4,6,7,5][4, 6, 7, 5]。

请输出执行该操作后 MEX⁡(a)\operatorname{MEX}(a)∗^{\text{∗}} 的最大可能值。

∗^{\text{∗}}MEX⁡(a)\operatorname{MEX}(a) 定义为不在数组中出现的最小非负整数。例如,MEX⁡([1,2,0,5])=3\operatorname{MEX}([1, 2, 0, 5]) = 3,而 MEX⁡([1,2,4,9])=0\operatorname{MEX}([1, 2, 4, 9]) = 0。

输入格式

The first line of the input contains a single integer tt (1≤t≤10001 \leq t \leq 1000) — the number of test cases.

The first line of each test case contains a single integer nn (1≤n≤30001 \le n \le 3000) — the length of array aa.

The second line contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (−109≤ai≤109-10^9 \le a_i \le 10^9) — the array aa.

It is guaranteed that the sum of nn over all test cases does not exceed 30003000.

输入的第一行包含一个整数 tt(1≤t≤10001 \leq t \leq 1000),表示测试用例的数量。

每个测试用例的第一行包含一个整数 nn(1≤n≤30001 \le n \le 3000),表示数组 aa 的长度。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(−109≤ai≤109-10^9 \le a_i \le 10^9),即数组 aa。

保证所有测试用例的 nn 之和不超过 30003000。

输出格式

For each test case, output the maximum possible value of MEX⁡(a)\operatorname{MEX}(a) after the operation has been performed.

对于每个测试用例,输出执行操作后 MEX⁡(a)\operatorname{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=−4x = -4 makes a=[0]a = [0], and MEX⁡([0])=1\operatorname{MEX}([0]) = 1.

For the second test case, the MEX⁡\operatorname{MEX} is already 44, which is the highest possible, so we can perform the operation with x=0x = 0, which will not change the array.

对于第一个测试用例,执行 x=−4x = -4 的操作后,数组变为 a=[0]a = [0],此时 MEX⁡([0])=1\operatorname{MEX}([0]) = 1。

对于第二个测试用例,当前 MEX⁡\operatorname{MEX} 已为 44,这已是可能的最大值,因此我们可以执行 x=0x = 0 的操作,该操作不会改变数组。

输入解题思路,AI测评打分。不知道怎么写?

首页