-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMex_Max.java
More file actions
49 lines (38 loc) · 883 Bytes
/
Copy pathMex_Max.java
File metadata and controls
49 lines (38 loc) · 883 Bytes
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
import java.util.*;
public class Mex_Max{
public static int mex(ArrayList<Integer> a ) {
int mex=0;
while(a.contains(mex))
mex++;
return mex;
}
public static int solve(ArrayList<Integer> a , int k){
int c=0;
if(mex(a)>Collections.max(a)) return a.size()+k;
while(k>0) {
int s=Math.round(((Collections.max(a) + mex(a))/2));
if(a.contains(s)==false){
a.add(s);
c++;
}
k--;
}
return a.size() + c;
}
public static void main(String args[]){
Scanner in = new Scanner(System.in);
ArrayList<Integer> liste = new ArrayList<Integer>();
int t=in.nextInt() ;
while(t>0)
{
int n =in.nextInt();
int k =in.nextInt();
for(int i=0 ; i<n ; i++) {
int r = in.nextInt();
liste.add(r);
}
System.out.println(solve(liste , k));
t--;
}
}
}