blob: b5ee47f7d66589b5fde191a6dfc9c0d2a63fef9b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
#include <algorithm>
#include <iostream>
#include <vector>
std::vector<int> readn(int n) {
std::vector<int> v(n);
for (int i = 0; i < n; i++)
std::cin >> v[i];
return v;
}
int main() {
int n, m, k;
std::cin >> n >> m >> k;
auto a = readn(n);
auto b = readn(m);
std::sort(a.begin(), a.end());
std::sort(b.begin(), b.end());
size_t s{0}, i{0}, j{0};
while (i < a.size() && j < b.size()) {
if (b[j] > a[i] + k) i++;
else if (b[j] < a[i] - k) j++;
else { s++; i++; j++; }
}
std::cout << s << "\n";
}
|