308299: CF1496B. Max and Mex
Memory Limit:256 MB
Time Limit:1 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
Max and Mex
题意翻译
[题目链接](https://codeforces.com/problemset/problem/1496/B) 给出一个长度大小为 $n$ 的可重集合 $S$(集合内允许有),保证这 $n$ 个数互不相同且非负。 接下来,你需要将下面操作进行 $k$ 次: 将 $\lceil \frac{a+b}{2}\rceil$ 加入集合(注意这里是**可重集**),其中 $a=\operatorname{mex}(S)$, $b=\max(S)$。 这里 $\operatorname{mex}(S)$ 表示集合 $S$ 中没有出现过的最小的非负整数,$\max(S)$ 表示 $S$ 中的最大整数。 求 $k$ 次操作后,集合 $S$ 中有多少个不同的数。 ### 输入格式 **本题有多组数据** 第一行一个整数 $T$,表示数据的组数。 对于每组数据: 第一行两个整数 $n,k$,表示集合初始长度和操作次数。 第二行 $n$ 个整数,表示 $a_{1 \dots n}$。 ### 输出格式 对于每组数据,输出一行一个整数表示答案。 **说明与提示** $1\le T \le 100$ $1\le n \le 10^5$ $0 \le a_i,k \le 10^9$ $\sum n\le 10^5$题目描述
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. You will perform the following operation $ k $ times: - 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. 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: - $ \operatorname{mex}(\{1,4,0,2\})=3 $ ; - $ \operatorname{mex}(\{2,5,1\})=0 $ . Your task is to calculate the number of distinct elements in $ S $ after $ k $ operations will be done.输入输出格式
输入格式
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. 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. 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. It is guaranteed that the sum of $ n $ over all test cases does not exceed $ 10^5 $ .
输出格式
For each test case, print the number of distinct elements in $ S $ after $ k $ operations will be done.
输入输出样例
输入样例 #1
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
输出样例 #1
4
4
3
5
3