-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
44 lines (35 loc) · 939 Bytes
/
main.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
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
inline void solve() {
int n, m, k;
cin >> n >> m >> k;
vector<ll> want(n), got(m);
for (int i = 0; i < n; ++i) cin >> want[i];
for (int i = 0; i < m; ++i) cin >> got[i];
sort(want.begin(), want.end(), greater<>());
sort(got.begin(), got.end(), greater<>());
int result = 0;
while (!want.empty() && !got.empty()) {
if (want.back() < got.back()) {
if (got.back() - k <= want.back()) {
++result;
got.pop_back();
}
want.pop_back();
} else { // want.back() >= got.back()
if (want.back() - k <= got.back()) {
++result;
want.pop_back();
}
got.pop_back();
}
}
cout << result;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
solve();
return 0;
}