apartments.cpp (745B)
1 #include <bits/stdc++.h> 2 3 using namespace std; 4 5 using ui = unsigned int; 6 using l = long; 7 using ul = unsigned long; 8 using ll = long long; 9 using ull = unsigned long long; 10 11 using vi = vector<int>; 12 using vui = vector<ui>; 13 using vl = vector<l>; 14 using vul = vector<ul>; 15 using vll = vector<ll>; 16 using vull = vector<ull>; 17 18 void solve() 19 { 20 int n, m, k; 21 cin >> n >> m >> k; 22 int a[n]; 23 int b[m]; 24 for (int i = 0; i < n; i++) 25 cin >> a[i]; 26 27 for (int i = 0; i < m; i++) 28 cin >> b[i]; 29 30 sort(a, a+n); 31 sort(b, b+m); 32 33 int res = 0; 34 int i = 0, j = 0; 35 while (i < n && j < m) { 36 if (a[i] < b[j] - k) { 37 i++; 38 } else if (a[i] > b[j] + k) { 39 j++; 40 } else { 41 i++; 42 j++; 43 res++; 44 } 45 } 46 47 cout << res << "\n"; 48 49 return; 50 } 51 52 int main() 53 { 54 solve(); 55 }