CF1496B.Max and Mex

传统题 时间 2000 ms 内存 256 MiB 5 尝试 1 已通过 1 标签

Max and Mex

You are given a multiset SS initially consisting of nn distinct non-negative integers. A multiset is a set, that can contain some elements multiple times.

You will perform the following operation kk times:

  • Add the element ⌈a+b2⌉\lceil\frac{a+b}{2}\rceil (rounded up) into SS, where a=mex⁡(S)a = \operatorname{mex}(S) and b=max⁡(S)b = \max(S). If this number is already in the set, it is added again.

Here max⁡\operatorname{max} of a multiset denotes the maximum integer in the multiset, and mex⁡\operatorname{mex} of a multiset denotes the smallest non-negative integer that is not present in the multiset. For example:

  • mex⁡({1,4,0,2})=3\operatorname{mex}(\{1,4,0,2\})=3;
  • mex⁡({2,5,1})=0\operatorname{mex}(\{2,5,1\})=0.

Your task is to calculate the number of distinct elements in SS after kk operations will be done.

Input

The input consists of multiple test cases. The first line contains a single integer tt (1≤t≤1001\le t\le 100) — the number of test cases. The description of the test cases follows.

The first line of each test case contains two integers nn, kk (1≤n≤1051\le n\le 10^5, 0≤k≤1090\le k\le 10^9) — the initial size of the multiset SS and how many operations you need to perform.

The second line of each test case contains nn distinct integers a1,a2,…,ana_1,a_2,\dots,a_n (0≤ai≤1090\le a_i\le 10^9) — the numbers in the initial multiset.

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

Output

For each test case, print the number of distinct elements in SS after kk operations will be done.

Note

In the first test case, S={0,1,3,4}S=\{0,1,3,4\}, a=mex⁡(S)=2a=\operatorname{mex}(S)=2, b=max⁡(S)=4b=\max(S)=4, ⌈a+b2⌉=3\lceil\frac{a+b}{2}\rceil=3. So 33 is added into SS, and SS becomes {0,1,3,3,4}\{0,1,3,3,4\}. The answer is 44.

In the second test case, S={0,1,4}S=\{0,1,4\}, a=mex⁡(S)=2a=\operatorname{mex}(S)=2, b=max⁡(S)=4b=\max(S)=4, ⌈a+b2⌉=3\lceil\frac{a+b}{2}\rceil=3. So 33 is added into SS, and SS becomes {0,1,3,4}\{0,1,3,4\}. The answer is 44.

Samples

5
4 1
0 1 3 4
3 1
0 1 4
3 0
0 1 4
3 2
0 1 2
3 2
1 2 3
4
4
3
5
3

在线编程 IDE

建议全屏模式获得最佳体验