-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApartment.java
More file actions
37 lines (37 loc) · 1.03 KB
/
Copy pathApartment.java
File metadata and controls
37 lines (37 loc) · 1.03 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
import java.util.Arrays;
import java.util.Scanner;
public class Apartment {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int applicants = sc.nextInt();
int apartments = sc.nextInt();
int diff = sc.nextInt();
int[] appSize = new int[applicants];
int[] apartSize = new int[apartments];
for(int i = 0; i<applicants; i++){
appSize[i] = sc.nextInt();
}
Arrays.sort(appSize);
for(int j = 0; j<apartments; j++){
apartSize[j] = sc.nextInt();
}
Arrays.sort(apartSize);
Arrays.sort(appSize);
int i = 0;
int j = 0;
int ans = 0;
while (i < applicants && j < apartments) {
if (Math.abs(appSize[i]-apartSize[j]) <= diff){
i++;
j++;
ans++;
} else if(appSize[i]>apartSize[j]){
j++;
} else{
i++;
}
}
System.out.println(ans);
sc.close();
}
}