Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <set>
- using namespace std;
- struct event {
- int type; // 1 - прибытие 0 -отправление
- int time_1;
- int time_2;
- int station;
- event(int type, int time_1, int time_2, int station) : type(type), time_1(time_1), time_2(time_2), station(station) {}
- };
- bool operator <(event const& a, event const& other) {
- return a.time_1 < other.time_1 || (a.time_1 == other.time_1 && a.type > other.type);
- }
- int main()
- {
- int t;
- cin >> t;
- int n;
- cin >> n;
- set<event> arr;
- vector<int> train1;
- vector<int> train2;
- for (int i = 0; i < n; i++) {
- int a, b;
- cin >> a >> b;
- arr.insert(event(0, a, b, 1));
- }
- int m;
- cin >> m;
- for (int i = 0; i < m; i++) {
- int a, b;
- cin >> a >> b;
- arr.insert(event(0, a, b, 2));
- }
- while (!arr.empty()) {
- event cur = *arr.begin();
- arr.erase(arr.begin());
- if (cur.type == 0) {
- if (cur.station == 1) {
- if ((int)train1.size() > 0) {
- arr.insert(event(1, cur.time_2 + t, -1, 2));
- train1.pop_back();
- }
- else {
- train1.push_back(0);
- arr.insert(event(1, cur.time_2 + t, -1, 2));
- train1.erase(train1.begin());
- }
- }
- else {
- if ((int)train2.size() > 0) {
- arr.insert(event(1, cur.time_2 + t, -1, 1));
- train2.pop_back();
- }
- else {
- arr.insert(event(1, cur.time_2 + t, -1, 1));
- }
- }
- }
- else {
- if (cur.station == 1) {
- train1.push_back(0);
- }
- else {
- train2.push_back(0);
- }
- }
- }
- int res = train1.size() + train2.size();
- cout << res << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement