Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define int long long
- #define all(a) a.begin(), a.end()
- #define pii pair<int, int>
- #define ull unsigned long long
- #define ld long double
- int n, m, t;
- vector<vector<pair<int, int> > > a;
- bool used[2][110];
- pair<int, int> find_new() {
- pair<int, int> ans;
- ans.first = -1;
- ans.second = -1;
- for (int i = 0; i < n; i++) {
- if (!used[0][i] && (ans.first == -1 || (a[ans.first][ans.second].first > a[0][i].first))) {
- ans.first = 0;
- ans.second = i;
- }
- }
- for (int i = 0; i < m; i++) {
- if (!used[1][i] && (ans.first == -1 || a[ans.first][ans.second].first > a[1][i].first)) {
- ans.first = 1;
- ans.second = i;
- }
- }
- return ans;
- }
- void sim(bool line, int ind) {
- used[line][ind] = 1;
- int nxtind = -1;
- if (line == 1) {
- for (int i = 0; i < n; i++) {
- if (!used[0][i] && a[0][i].first - a[line][ind].second >= t && (nxtind == -1 || a[0][nxtind].first > a[0][i].first)) {
- nxtind = i;
- }
- }
- if (nxtind == -1) return;
- sim(0, nxtind);
- } else {
- for (int i = 0; i < m; i++) {
- if (!used[1][i] && a[1][i].first - a[line][ind].second >= t && (nxtind == -1 || a[1][nxtind].first > a[1][i].first)) {
- nxtind = i;
- }
- }
- if (nxtind == -1) return;
- sim(1, nxtind);
- }
- }
- signed main()
- {
- cin >> t;
- cin >> n;
- a.resize(2);
- a[0].resize(n);
- for (int i = 0; i < n; i++) cin >> a[0][i].first >> a[0][i].second;
- cin >> m;
- a[1].resize(m);
- for (int i = 0; i < m; i++) cin >> a[1][i].first >> a[1][i].second;
- for (int i = 0; i < 110; i++) {
- used[0][i] = 0;
- used[1][i] = 0;
- }
- int ans = 0;
- pair<int, int> kek = find_new();
- while (kek.first != -1) {
- ans++;
- sim(kek.first, kek.second);
- kek = find_new();
- }
- cout << ans;
- }
- /*
- 6
- 7
- 38
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement