题面
原题
Solution
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<iostream>
#include<queue>
#define ll long long
#define file(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout)
using namespace std;
inline int gi(){
int sum=0,f=1;char ch=getchar();
while(ch>'9' || ch<'0'){if(ch=='-')f=-f;ch=getchar();}
while(ch>='0' && ch<='9'){sum=(sum<<3)+(sum<<1)+ch-'0';ch=getchar();}
return f*sum;
}
inline ll gl(){
ll sum=0,f=1;char ch=getchar();
while(ch>'9' || ch<'0'){if(ch=='-')f=-f;ch=getchar();}
while(ch>='0' && ch<='9'){sum=(sum<<3)+(sum<<1)+ch-'0';ch=getchar();}
return f*sum;
}
int a[100010],sum[100010];
int main(){
int i,j,n,m,k,w;
n=gi();w=gi();
for(i=1;i<=n;i++){
int x=gi(),b=gi();
a[x]+=b;
}
for(i=1;i<=100000;i++)
sum[i]=sum[i-1]+a[i];
int ans=0;
for(i=1;i<=100000-w;i++)
ans=max(ans,sum[i+w]-sum[i]);
printf("%d\n",ans);
return 0;
}