Josif_tepe

Untitled

Nov 5th, 2025
417
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.94 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <bits/stdc++.h>
  4. using namespace std;
  5.  
  6. const int maxn = 1e5 + 10;
  7. int n, m;
  8. int maski[maxn], zenski[maxn];
  9. int main()
  10. {
  11.     cin >> n;
  12.    
  13.     for(int i = 0; i < n; i++) {
  14.         cin >> maski[i];
  15.        
  16.     }
  17.    
  18.     cin >> m;
  19.     for(int i = 0; i < m; i++) {
  20.         cin >> zenski[i];
  21.     }
  22.    
  23.     int R, k;
  24.     cin >> R >> k;
  25.     sort(maski, maski + n);
  26.     sort(zenski, zenski + m);
  27.    
  28.    
  29.     int res = 0;
  30.     for(int i = 0, j = k - 1; j < m; i++, j++) {
  31.         int A = zenski[j] - R;
  32.         int B = zenski[i] + R;
  33.        
  34.         int idx1 = lower_bound(maski, maski + n, A) - maski;
  35.         int idx2 = upper_bound(maski, maski + n, B) - maski;
  36.        
  37.         if(idx1 >= 0 and idx1 < n and idx2 >= 0 and idx2 < n) {
  38.             res = max(res,  idx2 - idx1);
  39.         }
  40.        
  41.        
  42.     }
  43.     cout << res << endl;
  44.    
  45.    
  46.    
  47.      return 0;
  48. }
  49.  
Advertisement
Add Comment
Please, Sign In to add comment