-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path424-max-and-mex.cpp
More file actions
83 lines (77 loc) · 1.44 KB
/
Copy path424-max-and-mex.cpp
File metadata and controls
83 lines (77 loc) · 1.44 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
* Max and Mex [1496B]
* Problem: https://codeforces.com/problemset/problem/1496/B
* Verdict: ACCEPTED Solved: 2021-12-30
* Language: C++20 (GCC 11-64)
* Runtime: 62 ms Memory: 5800 KB
* Tags: math
* Author: team "Za Nakebo Pie" (Mr.Pie, BidoTeima)
* Source: https://codeforces.com/contest/1496/submission/141186856
*/
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
vector<int>v;
pair<int,int>getmex()
{
sort(v.begin(),v.end());
int c=0;
for(int i=0;i<v.size();i++)
{
if(v[i]==c)c++;
}
return {c,v.back()};
}
void solve()
{
v.clear();
int n,k;
cin>>n>>k;
set<int>st;
for(int i=0;i<n;i++)
{
int x;
cin>>x;
v.pb(x);
st.insert(x);
}
if(k == 0)
{
cout<<n<<endl;
return;
}
//for(k=1;k<=15;k++)
// {
pair<int,int>xx=getmex();
int mex = xx.first;
int mx=xx.second;
// v.pb((mex+mx)/2 + ((mex+mx)%2));
/* for(int i=0;i<v.size();i++)
{
cout<<v[i]<<" ";
}
cout<<endl;*/
if(mex>mx)
{
cout<<mex+k<<endl;
return;
}
else
{
st.insert((mex+mx)/2 + ((mex+mx)%2));
cout<<st.size()<<endl;
return;
}
//}
}
int32_t main()
{
ios_base::sync_with_stdio(0);
int t=1;
cin>>t;
while(t--)
{
solve();
}
}