Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int main() {
- int n, m, k;
- cin >> n >> m >> k;
- multiset<int> ms;
- vector<int> a(n), b(m);
- for(int i = 0; i < n; i++) {
- cin >> a[i];
- }
- for(int i = 0; i < m; i++) {
- cin >> b[i];
- ms.insert(b[i]);
- }
- sort(a.begin(), a.end());
- sort(b.begin(), b.end());
- int res = 0;
- for(int i = 0; i < n; i++) {
- int x = a[i] - k;
- multiset<int>::iterator it = ms.lower_bound(x);
- if(*it >= x and *it <= a[i] + k) {
- res++;
- ms.erase(it);
- }
- }
- cout << res << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement