Advertisement
Guest User

Untitled

a guest
Dec 15th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. vector<ll> used[2];
  2. vector<pll> stations[2];
  3.  
  4. ll n, m, t;
  5. ll ans = 0;
  6. void solve(ll id, ll st) {
  7. used[st][id] = 1;
  8. for (int i = 0; i < stations[st^1].size(); i++) {
  9. if (!used[st^1][i] && stations[st ^ 1][i].first >= stations[st][id].second + t) {
  10. solve(i, st ^ 1);
  11. break;
  12. }
  13. }
  14. }
  15.  
  16. ll a, b;
  17. ll l1 = 0, l2 = 0;
  18.  
  19. int main() {
  20. std::ios::sync_with_stdio(0);
  21. cin >> t;
  22. cin >> n;
  23.  
  24. for (int i = 0; i < n; i++) {
  25. cin >> a >> b;
  26. stations[0].push_back(mp(a, b));
  27. }
  28.  
  29. used[0].resize(n);
  30. sort(all(stations[0]));
  31.  
  32.  
  33. cin >> m;
  34. for (int i = 0; i < m; i++) {
  35. cin >> a >> b;
  36. stations[1].push_back(mp(a, b));
  37. }
  38.  
  39. used[1].resize(m);
  40. sort(all(stations[1]));
  41.  
  42.  
  43. while (l1 < n || l2 < m) {
  44. while (l1 < n && used[0][l1])
  45. l1++;
  46.  
  47. while (l2 < m && used[1][l2])
  48. l2++;
  49.  
  50. if (l1 >= n && l2 >= m)
  51. break;
  52.  
  53. ll t_s1 = 1e9, t_s2 = 1e9;
  54.  
  55. if (l1 < n)
  56. t_s1 = stations[0][l1].first;
  57.  
  58. if (l2 < m)
  59. t_s2 = stations[1][l2].first;
  60.  
  61. if (t_s1 < t_s2)
  62. solve(l1, 0);
  63. else
  64. solve(l2, 1);
  65. ans++;
  66. }
  67.  
  68. cout << ans;
  69. rt 0;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement