-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcses_1084.cpp
49 lines (40 loc) · 1.03 KB
/
cses_1084.cpp
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// #define DEBUG
#define MAXN 2000000000
#define ll long long int
#include <bits/stdc++.h>
using namespace std;
int main() {
#ifdef DEBUG
freopen("in.in", "r", stdin);
#endif
ios_base::sync_with_stdio(0);
cin.tie(0);
ll n, m, k;
cin >> n >> m >> k;
vector<ll> applicant(n);
vector<ll> appartment(m);
for (int i = 0; i < n; ++i)
cin >> applicant[i];
for (int i = 0; i < m; ++i)
cin >> appartment[i];
sort(applicant.begin(), applicant.end());
sort(appartment.begin(), appartment.end());
ll ans = 0;
ll request = 0;
ll resource = 0;
while (request < n && resource < m) {
if ((appartment[resource] - k <= applicant[request]) &&
(applicant[request] <= appartment[resource] + k)) {
ans++;
resource++;
request++;
} else {
if (appartment[resource] < applicant[request])
resource++;
else
request++;
}
}
cout << ans << endl;
return 0;
}