-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApartments.cpp
More file actions
40 lines (37 loc) · 997 Bytes
/
Copy pathApartments.cpp
File metadata and controls
40 lines (37 loc) · 997 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
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int apartments() {
int applicants, apartments, difference;
cin >> applicants;
cin >> apartments;
cin >> difference;
vector<long> desiredSizes, sizes;
for(int i = 1; i <= applicants; i++) {
long a;
cin >> a;
desiredSizes.push_back(a);
}
for(int i = 1; i <= apartments; i++) {
long a;
cin >> a;
sizes.push_back(a);
}
sort(desiredSizes.begin(), desiredSizes.end());
sort(sizes.begin(), sizes.end());
int counter = 0;
int res = 0;
for(int a = 0; a < desiredSizes.size(); a++) {
while(counter < sizes.size() && desiredSizes[a] >= sizes[counter] - difference) {
if(abs(desiredSizes[a] - sizes[counter]) <= difference) {
res += 1;
counter += 1;
break;
}
counter += 1;
}
}
cout << res << endl;
return 0;
}