Advertisement
Josif_tepe

Untitled

Oct 28th, 2022
1,173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.80 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <cmath>
  4. using namespace std;
  5.  
  6. int main() {
  7.     int n, m, k;
  8.     cin >> n >> m >> k;
  9.    
  10.     int apartments[n], applicants[m];
  11.    
  12.     for(int i = 0; i < n; i++) {
  13.         cin >> apartments[i];
  14.     }
  15.    
  16.     for(int i = 0; i < m; i++) {
  17.         cin >> applicants[i];
  18.     }
  19.    
  20.     sort(apartments, apartments + n);
  21.     sort(applicants, applicants + m);
  22.    
  23.     int i = 0, j = 0;
  24.     int result = 0;
  25.    
  26.    
  27.     while(i < n and j < m) {
  28.         if(abs(apartments[i] - applicants[j]) <= k) {
  29.             i++;
  30.             j++;
  31.             result++;
  32.         }
  33.         else if(apartments[i] < applicants[j]) {
  34.             i++;
  35.         }
  36.         else {
  37.             j++;
  38.         }
  39.     }
  40.     cout << result << endl;
  41.     return 0;
  42. }
  43.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement