-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1496B.cpp
More file actions
51 lines (45 loc) · 1.41 KB
/
1496B.cpp
File metadata and controls
51 lines (45 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long int lli;
typedef vector<int> vi;
typedef vector<long long int> vlli;
#define pb push_back
#define pi 3.1415
const lli MOD= 1e9+7;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);cout.tie(NULL);
lli t;cin>>t;
while(t--){
int n,k;cin>>n>>k;
vi arr(n);
for(int i=0;i<n;i++){
cin>>arr[i];
}
if(k>0){
sort(arr.begin(),arr.end());
int mex,maxx=arr[n-1];
if(n==1 && arr[0]!=0){mex=0;}
else if(n==1 && arr[0]==0){mex=1;}
else{
for(int i=0;i<n-1;i++){
if(arr[i+1]!=arr[i]+1){
mex=arr[i]+1;
break;
}
}
}
int elem=(maxx+1+mex)/2;
auto it=find(arr.begin(),arr.end(),elem);
if(mex<maxx && it==arr.end())
cout<<n+1<<"\n";
else if(mex<maxx && it!=arr.end())
cout<<n<<"\n";
else
cout<<n+k<<"\n";
}
else{cout<<n<<"\n";}
}
return 0;
}