Untitled

mail@pastecode.io avatar
unknown
plain_text
15 days ago
826 B
3
Indexable
Never
// y.ha
#include <bits/stdc++.h>
#define maxn 100010
using namespace std;

struct dirt {
    int c;
    int x;
};

int n,k,pre_mr[maxn],keep[maxn] ;
dirt vt[maxn] ;

bool ss(dirt a,dirt b) {
    return a.x < b.x ;
}
void inp() {
    cin >> n >> k ;
    for ( int i = 1; i <= n; i++ )
        cin >> vt[i].c >> vt[i].x ;
    sort(vt+1,vt+n+1,ss) ;
    for ( int i = 1; i <= n; i++ ) {
        pre_mr[i] = pre_mr[i-1] + vt[i].c ;
        keep[i] = vt[i].x ;
    }
}

long M_room(int here) {
    int fir = here - 1;
    int las = upper_bound(keep+1,keep+1+n,2*k+keep[here]) - keep - 1;
    return pre_mr[las] - pre_mr[fir];
}

int main()
{
    inp() ;
    int ma = 0 ;
    for ( int i = 1; i <= n; i++ ) {
        int mr = M_room(i) ;
        ma = max(mr,ma) ;
    }
    cout << ma ;
}
Leave a Comment