Advertisement
Josif_tepe

Untitled

May 18th, 2024
605
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.64 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int main() {
  4.     int n, m, k;
  5.     cin >> n >> m >> k;
  6.     multiset<int> ms;
  7.     vector<int> a(n), b(m);
  8.     for(int i = 0; i < n; i++) {
  9.         cin >> a[i];
  10.     }
  11.     for(int i = 0; i < m; i++) {
  12.         cin >> b[i];
  13.         ms.insert(b[i]);
  14.     }
  15.     sort(a.begin(), a.end());
  16.     sort(b.begin(), b.end());
  17.     int res = 0;
  18.     for(int i = 0; i < n; i++) {
  19.         int x = a[i] - k;
  20.         multiset<int>::iterator it = ms.lower_bound(x);
  21.         if(*it >= x and *it <= a[i] + k) {
  22.             res++;
  23.             ms.erase(it);
  24.         }
  25.     }
  26.     cout << res << endl;
  27.     return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement