-
Notifications
You must be signed in to change notification settings - Fork 0
/
BerSuBall.java
67 lines (65 loc) · 1.52 KB
/
BerSuBall.java
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
import java.util.* ;
public class BerSuBall
{
private static final boolean debug = false ;
public static void main(String args[]) throws Exception
{
Scanner in = new Scanner(System.in) ;
int b = in.nextInt() ;
int[] B = new int[b] ;
for(int i=0;i<b;i++)
{
B[i] = in.nextInt() ;
}
int g = in.nextInt() ;
int[] G = new int[g] ;
for(int i=0;i<g;i++)
{
G[i] = in.nextInt() ;
}
System.out.println(solve(B,G)) ;
}
static int solve(int[] B,int[] G)
{
Arrays.sort(B) ;
int max = findMax(G) ;
if(debug)
{
System.out.println("max :"+max) ;
}
int b = B.length ;
int g = G.length ;
int[] temp = new int[max+1] ;
for(int i=0;i<g;i++)
{
temp[G[i]]++ ;
}
int sum = 0 ;
for(int i=0;i<b;i++)
{
if(B[i]-1<=max && B[i]-1>0 && temp[B[i]-1]>0)
{
temp[B[i]-1]-- ;
sum++ ;
}
else if(B[i]<=max&&temp[B[i]]>0)
{
temp[B[i]]-- ;
sum++ ;
}
else if(B[i]+1<=max && temp[B[i]+1]>0)
{
temp[B[i]+1]-- ;
sum++ ;
}
}
return sum ;
}
static int findMax(int[] G)
{
int max = 0;
for(int el:G)
max = max<el?el:max ;
return max ;
}
}