-
-
Notifications
You must be signed in to change notification settings - Fork 110
/
Copy pathBeautifulPairs.java
33 lines (31 loc) · 943 Bytes
/
BeautifulPairs.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
import java.io.*;
import java.util.*;
public class Solution {
public static void main(String[] args) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int n=Integer.parseInt(br.readLine());
int a[]=new int[n];
int b[]=new int[n];
String s1[]=br.readLine().split(" ");
String s2[]=br.readLine().split(" ");
for(int i=0;i<n;i++){
a[i]=Integer.parseInt(s1[i]);
b[i]=Integer.parseInt(s2[i]);
}
int count1[]=new int[1000];
int count2[]=new int[1000];
for(int i=0;i<n;i++){
count1[a[i]-1]++;
count2[b[i]-1]++;
}
int count=0;
for(int i=0;i<1000;i++){
count+=Math.min(count1[i],count2[i]);
}
if(count<n)
count++;
else if(count==n)
count--;
System.out.println(count);
}
}