Advertisement
Josif_tepe

Untitled

Oct 3rd, 2021
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.39 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <fstream>
  5. #include <cmath>
  6. using namespace std;
  7.  
  8. int main() {
  9.     int n;
  10.     cin >> n;
  11.     int maski[n];
  12.     for(int i = 0; i < n; i++) {
  13.         cin >> maski[i];
  14.     }
  15.     sort(maski, maski + n);
  16.  
  17.     int m;
  18.     cin >> m;
  19.     int zenski[m];
  20.     for(int i = 0; i < m; i++) {
  21.         cin >> zenski[i];
  22.     }
  23.     sort(zenski, zenski + m);
  24.  
  25.     int razlika, K;
  26.     cin >> razlika >> K;
  27.     int rezultat = 0;
  28.     for(int i = 0; i + K - 1 < m; i++) {
  29.         int najgolem = zenski[i] + razlika;
  30.         int najmal = zenski[i + K - 1] - razlika;
  31.         int L = 0, R = n;
  32.         while(L < R) {
  33.             int mid = L + (R - L) / 2;
  34.             if(najmal <= maski[mid]) {
  35.                 R = mid;
  36.             }
  37.             else {
  38.                 L = mid + 1;
  39.             }
  40.         }
  41.         if(L < n and maski[L] < najmal) {
  42.             L++;
  43.         }
  44.         int L_tmp = L;
  45.         L = 0;
  46.         R = n;
  47.         while(L < R) {
  48.             int mid = L + (R - L) / 2;
  49.             if(najgolem >= maski[mid]) {
  50.                 L = mid + 1;
  51.             }
  52.             else {
  53.                 R = mid;
  54.             }
  55.         }
  56.         if(L < n and maski[L] <= najgolem) {
  57.             L++;
  58.         }
  59.        
  60.         rezultat = max(rezultat, L - L_tmp);
  61.     }
  62.     cout << rezultat << endl;
  63.     return 0;
  64. }
  65.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement