Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- #include <vector>
- #include <set>
- #include <map>
- #include <sstream>
- #include <cstdio>
- #include <algorithm>
- #include <stack>
- #include <queue>
- #include <cmath>
- #include <iomanip>
- #include <fstream>
- //#include <bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- const ll INF = (1 << 30);
- const ll inf = (1LL << 60LL);
- const int maxn = 1e5 + 5;
- int main(int argc, const char * argv[]) {
- ios_base::sync_with_stdio(false);
- int n, m, k;
- cin >> n >> m >> k;
- vector<int> apartments(n), applicants(m);
- for(int i = 0; i < n; ++i) {
- cin >> apartments[i];
- }
- for(int i = 0; i < m; ++i) {
- cin >> applicants[i];
- }
- sort(apartments.begin(), apartments.end());
- sort(applicants.begin(), applicants.end());
- int i = 0, j = 0;
- int ret = 0;
- while(i < n and j < m /*to the minimum of (n, m)*/) {
- if(abs(apartments[i] - applicants[j]) <= k) {
- ++i;
- ++j;
- ++ret;
- continue;
- }
- if(apartments[i] < applicants[j]) {
- ++i;
- }
- else {
- ++j;
- }
- }
- cout << ret << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment