Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- vector<ll> used[2];
- vector<pll> stations[2];
- ll n, m, t;
- ll ans = 0;
- void solve(ll id, ll st) {
- used[st][id] = 1;
- for (int i = 0; i < stations[st^1].size(); i++) {
- if (!used[st^1][i] && stations[st ^ 1][i].first >= stations[st][id].second + t) {
- solve(i, st ^ 1);
- break;
- }
- }
- }
- ll a, b;
- ll l1 = 0, l2 = 0;
- int main() {
- std::ios::sync_with_stdio(0);
- cin >> t;
- cin >> n;
- for (int i = 0; i < n; i++) {
- cin >> a >> b;
- stations[0].push_back(mp(a, b));
- }
- used[0].resize(n);
- sort(all(stations[0]));
- cin >> m;
- for (int i = 0; i < m; i++) {
- cin >> a >> b;
- stations[1].push_back(mp(a, b));
- }
- used[1].resize(m);
- sort(all(stations[1]));
- while (l1 < n || l2 < m) {
- while (l1 < n && used[0][l1])
- l1++;
- while (l2 < m && used[1][l2])
- l2++;
- if (l1 >= n && l2 >= m)
- break;
- ll t_s1 = 1e9, t_s2 = 1e9;
- if (l1 < n)
- t_s1 = stations[0][l1].first;
- if (l2 < m)
- t_s2 = stations[1][l2].first;
- if (t_s1 < t_s2)
- solve(l1, 0);
- else
- solve(l2, 1);
- ans++;
- }
- cout << ans;
- rt 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement