Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define pi pair<int,int>
- #define x first
- #define y second
- using namespace std;
- class fcmp {
- public:
- bool operator()(const pi &a, const pi &b) const {
- return tie(a.y, a.x) < tie(b.y, b.x);
- };
- };
- void max_self(int &a, int b) {
- a = max(a, b);
- }
- int main() {
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- int N, W;
- cin >> N >> W;
- vector<pi> trees(N);
- for(pi &x : trees)
- cin >> x.x >> x.y;
- sort(trees.begin(), trees.end());
- set<pi,fcmp> edges{{-1, 0}, {W + 1, W}};
- multiset<int> gaps{W};
- int ans = 0, p = 0;
- for(int i = -1; i < N; ++i) {
- int x0 = 0;
- if(i != -1) {
- const pi &t = trees[i];
- x0 = t.x;
- auto pos = edges.find(t);
- auto a = prev(pos);
- auto b = next(pos);
- cout << i << endl;
- cout << "a: " << a->x << ' ' << a->y << endl;
- cout << "b: " << b->x << ' ' << b->y << endl;
- gaps.erase(gaps.find(t.y - a->y));
- gaps.erase(gaps.find(b->y - t.y));
- gaps.insert(b->y - a->y);
- edges.erase(pos);
- }
- if(p < i)
- p = i;
- int x1 = (p == N) ? W : trees[p].x;
- max_self(ans, min(x1 - x0, *gaps.rbegin()));
- while(p < N && trees[p].x - x0 <= *gaps.rbegin()) {
- cout << *gaps.rbegin() << endl;
- const pi &t = trees[p];
- auto b = edges.lower_bound(t);
- auto a = prev(b);
- gaps.erase(gaps.find(b->y - a->y));
- gaps.insert(t.y - a->y);
- gaps.insert(b->y - t.y);
- edges.insert(t);
- cout << i << ' ' << p << endl;
- cout << "t: " << t.x << ' ' << t.y << endl;
- cout << "b: " << b->x << ' ' << b->y << endl;
- cout << "a: " << a->x << ' ' << a->y << endl;
- cout << "dif " << b->y - a->y << endl;
- cout << "t.y-a->y " << t.y - a->y << endl;
- cout << "b->y-t.y " << b->y - t.y << endl;
- cout << *gaps.rbegin() << endl;
- cout << endl << endl;
- ++p;
- x1 = (p == N) ? W : trees[p].x;
- max_self(ans, min(x1 - x0, *gaps.rbegin()));
- }
- }
- cout << ans;
- }
Advertisement
Add Comment
Please, Sign In to add comment