Advertisement
Guest User

Untitled

a guest
Jan 19th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.04 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define f first
  3. #define s second
  4.  
  5. using namespace std;
  6. typedef pair <int, int> pii;
  7.  
  8. const int MAXN = 211111;
  9. const double eps = 0.5;
  10. vector <pii> a;
  11.  
  12. int main()
  13. {
  14.     ios_base::sync_with_stdio(0);
  15.     cin.tie(0);
  16.     int n, t;
  17.     cin >> n >> t;
  18.     a.resize(n);
  19.     vector <int> tmp(n);
  20.     for(int i = 0; i < n; i++){
  21.         int l, r;
  22.         cin >> l >> r;
  23.         a[i] = {l, r};
  24.         tmp[i] = l;
  25.     }
  26.     sort(a.begin(), a.end());
  27.     sort(tmp.begin(), tmp.end());
  28.     int ans = 0;
  29.     for(int i = 0; i < n; i++){
  30.         double cur_l = a[i].f - eps, cur_r = a[i].f + t - eps;
  31.         int cur_upper, cur_lower;
  32.         cur_upper = cur_lower = 0;
  33.         for(int j = i; j < n; j++)
  34.             if(a[j].f > cur_l && a[j].s < cur_r)cur_lower++;
  35.         int pos = lower_bound(tmp.begin(), tmp.end(), a[i].f) - tmp.begin();
  36.         for(int j = 0; j < pos; j++)
  37.             if(a[j].s > cur_r)cur_upper++;
  38.         ans = max(ans, cur_lower - cur_upper);
  39.     }
  40.     cout << ans << '\n';
  41.     return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement