aboutsummaryrefslogtreecommitdiff
path: root/cses/SortingAndSearching/Apartments/main.cpp
blob: 676f338ea6374aca0b95caae7fad26cb0a8bb21e (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
28
29
30
31
#include <algorithm>
#include<bits/stdc++.h>

using namespace std;

#define all(x) (x).begin(), (x).end()

int main () {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
  int n, m, k;
  cin >> n >> m >> k;
  set<int> taken;
  vector<int> v(n);
  vector<int> a(m);
  for (auto &x : v) cin >> x;
  for (auto &x : a) cin >> x;
  sort(all(a));
  int ans = 0;
  for (int i = 0; i < n; i++) {
    auto upper = *upper_bound(all(a), v[i]);
    auto lower = *lower_bound(all(a), v[i]);
    cerr << upper << " " << lower << "\n";
    if(!taken.count(i) && (upper <= v[i] + k || lower >= v[i] - k)) {
      taken.insert(i);
      ans++;
    }
  }
  cout << ans << '\n';

}