![](https://images2018.cnblogs.com/blog/1334471/201803/1334471-20180309183802879-1226458590.jpg)
对不起,常数小就是可以为所欲为的。
// luogu-judger-enable-o2
#include<cstdio>
#include<algorithm>
#include<iostream>
using namespace std;
struct node
{
int tree[100100];
int num;
int lowbit(int x)
{
return x&(-x);
}
void updata(int x,int i)
{
while(i<=num)
{
tree[i]+=x;
i+=lowbit(i);
}
}
int sum(int i)
{
int ans=0;
while(i>0)
{
ans+=tree[i];
i-=lowbit(i);
}
return ans;
}
int check(int l,int r)
{
return sum(r)-sum(l-1);
}
};
node bit;
int main()
{
int n,m;
scanf("%d%d",&n,&m);
bit.num=n;
int a,b;
for(int i=1;i<=n;i++)
{
scanf("%d%d",&a,&b);
bit.updata(b,a);
}
int ans=0;
for(int i=1;i+m-1<=n;i++)
ans=max(ans,bit.check(i,i+m-1));
printf("%d",ans);
}