1496B.md (2192B)
1 Source: https://codeforces.com/problemset/problem/1496/B 2 3 B. Max and Mex 4 5 time limit per test 6 7 1 second 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 You are given a multiset $S$ initially consisting of $n$ distinct non-negative integers. A multiset is a set, that can contain some elements multiple times. 22 23 You will perform the following operation $k$ times: 24 25 * Add the element $\lceil\frac{a+b}{2}\rceil$ (rounded up) into $S$, where $a = \operatorname{mex}(S)$ and $b = \max(S)$. If this number is already in the set, it is added again. 26 27 Here $\operatorname{max}$ of a multiset denotes the maximum integer in the multiset, and $\operatorname{mex}$ of a multiset denotes the smallest non-negative integer that is not present in the multiset. For example: 28 29 * $\operatorname{mex}(\{1,4,0,2\})=3$; 30 * $\operatorname{mex}(\{2,5,1\})=0$. 31 32 Your task is to calculate the number of distinct elements in $S$ after $k$ operations will be done. 33 34 Input 35 36 The input consists of multiple test cases. The first line contains a single integer $t$ ($1\le t\le 100$) — the number of test cases. The description of the test cases follows. 37 38 The first line of each test case contains two integers $n$, $k$ ($1\le n\le 10^5$, $0\le k\le 10^9$) — the initial size of the multiset $S$ and how many operations you need to perform. 39 40 The second line of each test case contains $n$ distinct integers $a_1,a_2,\dots,a_n$ ($0\le a_i\le 10^9$) — the numbers in the initial multiset. 41 42 It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$. 43 44 Output 45 46 For each test case, print the number of distinct elements in $S$ after $k$ operations will be done. 47 48 Example 49 50 Input 51 52 ``` 53 5 54 4 1 55 0 1 3 4 56 3 1 57 0 1 4 58 3 0 59 0 1 4 60 3 2 61 0 1 2 62 3 2 63 1 2 3 64 ``` 65 66 Output 67 68 ``` 69 4 70 4 71 3 72 5 73 3 74 ``` 75 76 Note 77 78 In the first test case, $S=\{0,1,3,4\}$, $a=\operatorname{mex}(S)=2$, $b=\max(S)=4$, $\lceil\frac{a+b}{2}\rceil=3$. So $3$ is added into $S$, and $S$ becomes $\{0,1,3,3,4\}$. The answer is $4$. 79 80 In the second test case, $S=\{0,1,4\}$, $a=\operatorname{mex}(S)=2$, $b=\max(S)=4$, $\lceil\frac{a+b}{2}\rceil=3$. So $3$ is added into $S$, and $S$ becomes $\{0,1,3,4\}$. The answer is $4$.