Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- #include <queue>
- using namespace std;
- struct trip {
- int t1, t2, s;
- };
- bool comp(trip a, trip b) {
- if (a.t1 < b.t1) {
- return true;
- }
- else if (a.t1 > b.t1) {
- return false;
- }
- else {
- if (a.t2 < b.t2) {
- return true;
- }
- else if (a.t2 > b.t2) {
- return false;
- }
- else {
- return a.s < b.s;
- }
- }
- }
- int main() {
- int t;
- cin >> t;
- int n;
- cin >> n;
- vector <trip> a(n);
- for (int i = 0; i < n; i++) {
- cin >> a[i].t1 >> a[i].t2;
- a[i].t2 += t;
- a[i].s = 1;
- }
- int m;
- cin >> m;
- a.resize(n + m);
- for (int i = n; i < n + m; i++) {
- cin >> a[i].t1 >> a[i].t2;
- a[i].t2 += t;
- a[i].s = 2;
- }
- sort(a.begin(), a.end(), comp);
- int c1 = 0, c2 = 0;
- int ans = 0;
- priority_queue <int, vector <int>, greater<int>> q1, q2;
- for (int i = 0; i < n + m; i++) {
- if (a[i].s == 1) {
- while (q1.size() > 0 && q1.top() <= a[i].t1) {
- q1.pop();
- c1++;
- }
- if (c1 == 0) {
- c1++;
- ans++;
- }
- c1--;
- q2.push(a[i].t2);
- }
- else {
- while (q2.size() > 0 && q2.top() <= a[i].t1) {
- q2.pop();
- c2++;
- }
- if (c2 == 0) {
- c2++;
- ans++;
- }
- c2--;
- q1.push(a[i].t2);
- }
- }
- cout << ans;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement