2226C.md (2254B)
1 Source: https://codeforces.com/problemset/problem/2226/C 2 3 C. Mental Monumental (Easy Version) 4 5 time limit per test 6 7 4 seconds 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 standard input 16 17 output 18 19 standard output 20 21 This is the easy version of this problem. The difference between the versions is that in this version, you are required to find only the value of $f(a)$. 22 23 For any array $[c_1, c_2, \ldots, c_m]$, we define $f(c)$ as the maximum possible $\operatorname{mex}(c)$$^{\text{∗}}$ that can be achieved by performing the following operation exactly once: 24 25 * Choose an integer array $[b_1, b_2, \ldots, b_m]$ such that $b_i \ge 1$ for all $1 \le i \le m$; 26 * Set $c_i := c_i \, \bmod \, b_i$$^{\text{†}}$ for every $1 \le i \le m$. 27 28 You are given an array $a$ consisting of $n$ non-negative integers. Determine the value of $f(a)$. 29 30 $^{\text{∗}}$$\operatorname{mex}(c)$ denotes the minimum excluded (MEX) of the integers in $c$. For example, $\operatorname{mex}([2,2,1])=0$ because $0$ does not belong to the array, and $\operatorname{mex}([0,3,1,2])=4$ because $0$, $1$, $2$, and $3$ appear in the array, but $4$ does not. 31 32 $^{\text{†}}$$u \bmod v$ denotes the remainder from dividing $u$ by $v$. 33 34 Input 35 36 Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows. 37 38 The first line of each testcase contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the length of the array $a$. 39 40 The second line of each testcase contains $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \le a_i \le 10^6$) — the elements of the array $a$. 41 42 It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$. It is guaranteed that the sum of $\max(a_1,a_2,\ldots,a_n)$ over all test cases does not exceed $10^6$. 43 44 Output 45 46 For each testcase, output a single integer — the value of $f(a)$. 47 48 Example 49 50 Input 51 52 ``` 53 4 54 55 4 56 57 0 1 2 3 58 59 2 60 61 6 7 62 63 6 64 65 8 1 7 6 4 3 66 67 9 68 69 9 9 8 2 4 4 3 5 3 70 ``` 71 72 Output 73 74 ``` 75 4 76 77 2 78 79 5 80 81 6 82 ``` 83 84 Note 85 86 For the first testcase, choosing $b = [1, 2, 3, 4]$ leaves $a$ unchanged and we have $\operatorname{mex}(a) = 4$. 87 88 For the second testcase, choosing $b = [3, 3]$ makes $a = [0, 1]$. Thus, we have $\operatorname{mex}(a) = 2$.