Alex_tz307

SAPO 2018 stadium

Dec 5th, 2020
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.33 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define pi pair<int,int>
  3. #define x first
  4. #define y second
  5.  
  6. using namespace std;
  7.  
  8. class fcmp {
  9.     public:
  10.         bool operator()(const pi &a, const pi &b) const {
  11.             return tie(a.y, a.x) < tie(b.y, b.x);
  12.         };
  13. };
  14.  
  15. void max_self(int &a, int b) {
  16.     a = max(a, b);
  17. }
  18.  
  19. int main() {
  20.     ios_base::sync_with_stdio(false);
  21.     cin.tie(nullptr);
  22.     cout.tie(nullptr);
  23.     int N, W;
  24.     cin >> N >> W;
  25.     vector<pi> trees(N);
  26.     for(pi &x : trees)
  27.         cin >> x.x >> x.y;
  28.     sort(trees.begin(), trees.end());
  29.     set<pi,fcmp> edges{{-1, 0}, {W + 1, W}};
  30.     multiset<int> gaps{W};
  31.     int ans = 0, p = 0;
  32.     for(int i = -1; i < N; ++i) {
  33.         int x0 = 0;
  34.         if(i != -1) {
  35.             const pi &t = trees[i];
  36.             x0 = t.x;
  37.             auto pos = edges.find(t);
  38.             auto a = prev(pos);
  39.             auto b = next(pos);
  40.             cout << i << endl;
  41.             cout << "a: " << a->x << ' ' << a->y << endl;
  42.             cout << "b: " << b->x << ' ' << b->y << endl;
  43.             gaps.erase(gaps.find(t.y - a->y));
  44.             gaps.erase(gaps.find(b->y - t.y));
  45.             gaps.insert(b->y - a->y);
  46.             edges.erase(pos);
  47.         }
  48.         if(p < i)
  49.             p = i;
  50.         int x1 = (p == N) ? W : trees[p].x;
  51.         max_self(ans, min(x1 - x0, *gaps.rbegin()));
  52.         while(p < N && trees[p].x - x0 <= *gaps.rbegin()) {
  53.             cout << *gaps.rbegin() << endl;
  54.             const pi &t = trees[p];
  55.             auto b = edges.lower_bound(t);
  56.             auto a = prev(b);
  57.             gaps.erase(gaps.find(b->y - a->y));
  58.             gaps.insert(t.y - a->y);
  59.             gaps.insert(b->y - t.y);
  60.             edges.insert(t);
  61.             cout << i << ' ' << p << endl;
  62.             cout << "t: " << t.x << ' ' << t.y << endl;
  63.             cout << "b: " << b->x << ' ' << b->y << endl;
  64.             cout << "a: " << a->x << ' ' << a->y << endl;
  65.             cout << "dif " << b->y - a->y << endl;
  66.             cout << "t.y-a->y " << t.y - a->y << endl;
  67.             cout << "b->y-t.y " << b->y - t.y << endl;
  68.             cout << *gaps.rbegin() << endl;
  69.             cout << endl << endl;
  70.             ++p;
  71.             x1 = (p == N) ? W : trees[p].x;
  72.             max_self(ans, min(x1 - x0, *gaps.rbegin()));
  73.         }
  74.     }
  75.     cout << ans;
  76. }
  77.  
Advertisement
Add Comment
Please, Sign In to add comment