fork download
  1. //
  2. // main.cpp
  3. // B - Apartments
  4. //
  5. // Created by Farrah Tharwat on 28/01/2023.
  6. //
  7.  
  8. #include <iostream>
  9. #include <set>
  10. using namespace std;
  11. void farrouha(){
  12. ios_base::sync_with_stdio(false);
  13. cin.tie(NULL);
  14. cout.tie(NULL);
  15. }
  16. int main() {
  17. farrouha;
  18. int n,m,k,cnt=0;
  19. multiset <int> mm;
  20. cin>>n>>m>>k;
  21. int nn [n];
  22. for(int i=0; i<n; i++)cin>>nn[i];
  23. while(m--){
  24. int x;
  25. cin>>x;
  26. mm.insert(x);
  27. }
  28. for(int i=0; i<n; i++){
  29. //cout<<nn[i]<<" "<<*mm.lower_bound(nn[i]-k)<<endl;
  30. int val = *mm.lower_bound(nn[i]-k);
  31. if(val<=(nn[i]+k) && mm.lower_bound(nn[i]-k)!=mm.end()){
  32. cnt++;
  33. mm.erase(mm.lower_bound(nn[i]-k));
  34. }
  35. }
  36. cout<<cnt<<"\n";
  37. }
  38.  
Success #stdin #stdout 0.01s 5520KB
stdin
4 3 5
60 45 80 60
30 60 75
stdout
2