Advertisement
sasa2742002

Untitled

Dec 2nd, 2021
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.17 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. #define T ll rrr;cin>>rrr;for(ll w1=0;w1<rrr;w1++)
  3. #define cin(vec,a) for(ll i=0;i<a && cin >> vec[i];i++)
  4. #define cout(vec,a) for(ll i=0;i<a && cout << vec[i];i++)
  5. #define MOD 1000000007
  6. #define PI 3.14159265
  7. #define ceil(a, b) ((a / b) + (a % b ? 1 : 0))
  8. #define all(v) v.begin(),v.end()
  9. #define rall(v) v.rbegin(),v.rend()
  10.  
  11. typedef long long ll;
  12. using namespace std;
  13.  
  14. void sasa()
  15. {
  16.     ios::sync_with_stdio(false);
  17.     cin.tie(nullptr);
  18.     cout.tie(nullptr);
  19. }
  20. // 20 21 31 35 39 41 49 74 86 90
  21. // 4 7 14 24 24 60 82 85 85 95
  22. void solve()
  23. {
  24.     ll n,m,k;
  25.     cin >> n >> m >> k;
  26.     vector<ll>vec1(n);
  27.     vector<ll>vec2(m);
  28.     cin(vec1,n);
  29.     cin(vec2,m);
  30.     ll l=0,r=0,counter=0;
  31.     sort(all(vec1));
  32.     sort(all(vec2));
  33.     while(l<m)
  34.     {
  35.         if(vec1[r] >= vec2[l]-k && vec1[r] <= vec2[l]+k)l++,counter++,r++;
  36.         else
  37.         {
  38.             if(vec1[r]> vec2[l]+k)l++;
  39.             else r++;
  40.         }
  41.  
  42.  
  43.     }
  44.     cout << counter;
  45.  
  46. }
  47.  
  48. int main()
  49. {
  50.     sasa();
  51.  
  52.     ll t = 1;
  53.     //cin >> t;
  54.     while (t--)
  55.     {
  56.         solve();
  57.         if(!t) break;
  58.         cout << "\n";
  59.     }
  60.  
  61.     return 0;
  62. }
  63.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement