Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define int long long
- #define pii pair<int, int>
- #define x1 x1228
- #define y1 y1228
- #define left left228
- #define right right228
- #define pb push_back
- #define eb emplace_back
- #define mp make_pair
- #define ff first
- #define ss second
- #define matr vector<vector<int> >
- #define all(x) x.begin(), x.end()
- using namespace std;
- typedef long long ll;
- typedef long double ld;
- const int maxn = 3e5 + 7, mod = 1e9 + 7, inf = 1e18, MAXN = 1e6 + 7;
- const double eps = 1e-9;
- mt19937 rnd(time(0));
- int n, t;
- pii seg[maxn];
- void solve() {
- cin >> n >> t;
- vector<int> check;
- for (int i = 0; i < n; ++i) {
- int a, b; cin >> a >> b;
- a *= 2;
- b *= 2;
- seg[i] = {a, b};
- check.pb(a);
- check.pb(a - 1);
- check.pb(b);
- check.pb(b + 1);
- }
- sort(all(check));
- check.erase(unique(all(check)), check.end());
- int ans = 0;
- for (auto v : check) {
- int cur = 0;
- int l = v;
- int r = l + 2 * t;
- for (int i = 0; i < n; ++i) {
- if (l < seg[i].ff && r > seg[i].ss) {
- ++cur;
- } else if (seg[i].ff < l && seg[i].ss > r) {
- --cur;
- }
- }
- ans = max(ans, cur);
- }
- cout << ans;
- }
- signed main() {
- #ifdef LOCAL1
- freopen("TASK.in", "r", stdin);
- freopen("TASK.out", "w", stdout);
- #else
- #endif // LOCAL
- ios_base::sync_with_stdio(false);
- cin.tie(0);
- cout.precision(20);
- cout << fixed;
- int t = 1;
- for (int i = 0; i < t; ++i)
- solve();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement