fork download
  1. #include <bits/stdc++.h>
  2. #include <ext/pb_ds/assoc_container.hpp>
  3.  
  4. using namespace std;
  5. using namespace __gnu_pbds;
  6.  
  7. typedef tree<
  8. pair<int, int>,
  9. null_type,
  10. less<pair<int, int>>,
  11. rb_tree_tag,
  12. tree_order_statistics_node_update> ordered_set;
  13.  
  14. int main()
  15. {
  16. //freopen("input.txt", "r", stdin);
  17. //freopen("output.txt", "w", stdout);
  18. ios::sync_with_stdio(0);
  19. cin.tie(0);
  20. int n, m, l;
  21. cin >> n >> m >> l;
  22. pair<int, int> sq[n];
  23. for(auto &it: sq)
  24. cin >> it.first >> it.second;
  25. sort(sq, sq + n);
  26. pair<int, int> po[m];
  27. for(auto &it: po)
  28. cin >> it.first >> it.second;
  29. set<int> fst;
  30. for(int i = 0; i < n; i++)
  31. fst.insert(sq[i].first);
  32. for(int i = 0; i < m; i++)
  33. fst.insert(po[i].first);
  34. sort(po, po + m);
  35. int ans = 0;
  36. int i = 0, j = 0, k = 0;
  37. ordered_set me;
  38. for(auto it: fst)
  39. {
  40. while(i < n && sq[i].first == it)
  41. me.insert({sq[i].second, i}), i++;
  42. while(sq[k].first + l < it)
  43. me.erase({sq[k].second, k}), k++;
  44. while(j < m && po[j].first == it)
  45. ans = max(ans, (int)me.order_of_key({po[j].second + 1, 0}) - (int)me.order_of_key({po[j].second - l, 0})), j++;
  46. }
  47. cout << ans << "\n";
  48. }
  49.  
Runtime error #stdin #stdout 0s 3464KB
stdin
Standard input is empty
stdout
Standard output is empty