-
Notifications
You must be signed in to change notification settings - Fork 0
/
apartments.cpp
52 lines (37 loc) · 927 Bytes
/
apartments.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
50
51
52
//
// Created by Tony on 8/15/2021.
//
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
typedef long long ll;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
ll n, m, k;
cin >> n >> m >> k;
vector<ll> ppl(n);
vector<ll> apts(m);
for (int i = 0; i < n; i++)
cin >> ppl[i];
for (int i = 0; i < m; i++)
cin >> apts[i];
sort(ppl.begin(), ppl.end());
sort(apts.begin(), apts.end());
ll count = 0;
for (int i = 0, j = 0; i < m && j < n;) {
if (apts[i] > ppl[j] + k) {
j++;
}
else if (apts[i] < ppl[j]-k)
i++;
else if (abs(apts[i] - ppl[j]) <= k) {
count++;
i++;
j++;
}
else
j++;
}
cout << count << endl;
}