josiftepe

Untitled

Oct 17th, 2020
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.21 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. #include <vector>
  4. #include <set>
  5. #include <map>
  6. #include <sstream>
  7. #include <cstdio>
  8. #include <algorithm>
  9. #include <stack>
  10. #include <queue>
  11. #include <cmath>
  12. #include <iomanip>
  13. #include <fstream>
  14. //#include <bits/stdc++.h>
  15. using namespace std;
  16. typedef long long ll;
  17. const ll INF = (1 << 30);
  18. const ll inf = (1LL << 60LL);
  19. const int  maxn = 1e5 + 5;
  20.  
  21. int main(int argc, const char * argv[]) {
  22.     ios_base::sync_with_stdio(false);
  23.     int n, m, k;
  24.     cin >> n >> m >> k;
  25.     vector<int> apartments(n), applicants(m);
  26.     for(int i = 0; i < n; ++i) {
  27.         cin >> apartments[i];
  28.     }
  29.     for(int i = 0; i < m; ++i) {
  30.         cin >> applicants[i];
  31.     }
  32.     sort(apartments.begin(), apartments.end());
  33.     sort(applicants.begin(), applicants.end());
  34.     int i = 0, j = 0;
  35.     int ret = 0;
  36.     while(i < n and j < m /*to the minimum of (n, m)*/) {
  37.         if(abs(apartments[i] - applicants[j]) <= k) {
  38.             ++i;
  39.             ++j;
  40.             ++ret;
  41.             continue;
  42.         }
  43.         if(apartments[i] < applicants[j]) {
  44.             ++i;
  45.         }
  46.         else {
  47.             ++j;
  48.         }
  49.     }
  50.     cout << ret << endl;
  51.     return 0;
  52. }
  53.  
Advertisement
Add Comment
Please, Sign In to add comment