Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define int long long
- using namespace std;
- int OPEN = 0;
- int SHUT = 1;
- int LEFT = 2;
- int INSIDE = 3;
- int RIGHT = 4;
- int n, t;
- struct comp {
- bool operator()(vector<int> const &a, vector<int> const &b) const {
- return a[0] < b[0];
- }
- };
- vector<vector<int> > kek;
- vector<pair<int, int> > status;
- string match(int i) {
- if (i == 2) return "LEFT";
- if (i == 3) return "INSIDE";
- else return "RIGHT";
- }
- void show() {
- for (int i = 0; i < n; i++) {
- cout << i << ' ' << match(status[i].first) << ' ' << match(status[i].second) << endl;
- }
- }
- signed main() {
- cin >> n >> t;
- for (int i = 0; i < n; i++) {
- int l, r;
- cin >> l >> r;
- vector<int> a(3);
- a[0] = l;
- a[1] = OPEN;
- a[2] = i;
- vector<int> b(3);
- b[0] = r;
- b[1] = SHUT;
- b[2] = i;
- kek.push_back(a);
- kek.push_back(b);
- }
- sort(kek.begin(), kek.end(), comp());
- status.resize(n, {RIGHT, RIGHT});
- int rep = 0;
- for (int l = 0, r = -1; l < kek.size(); l++) {
- int x = kek[l][0];
- while (r < kek.size() - 1 && kek[r + 1][0] - kek[l][0] < t) {
- r++;
- if (kek[r][1] == OPEN) {
- status[kek[r][2]].first = INSIDE;
- } else {
- status[kek[r][2]].second = INSIDE;
- }
- }
- int now = 0;
- for (int i = 0; i < n; i++) {
- if (status[i].first == INSIDE && status[i].second == INSIDE) {
- now++;
- } else if (status[i].first == LEFT && status[i].second == RIGHT) {
- now--;
- }
- }
- rep = max(rep, now);
- if (kek[l][1] == OPEN) {
- status[kek[l][2]].first = LEFT;
- } else {
- status[kek[l][2]].second = LEFT;
- }
- }
- cout << rep << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement