Josif_tepe

Untitled

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