Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #include <cmath>
- using namespace std;
- int main() {
- int n, m, k;
- cin >> n >> m >> k;
- int apartments[n], applicants[m];
- for(int i = 0; i < n; i++) {
- cin >> apartments[i];
- }
- for(int i = 0; i < m; i++) {
- cin >> applicants[i];
- }
- sort(apartments, apartments + n);
- sort(applicants, applicants + m);
- int i = 0, j = 0;
- int result = 0;
- while(i < n and j < m) {
- if(abs(apartments[i] - applicants[j]) <= k) {
- i++;
- j++;
- result++;
- }
- else if(apartments[i] < applicants[j]) {
- i++;
- }
- else {
- j++;
- }
- }
- cout << result << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement