#include <bits/stdc++.h>
using namespace std;
long long n,m,sum;
int ans;
struct abc {
long long x,t;
} a[100001];
bool cnt(abc x,abc y) {
return x.x<y.x;
}
int main() {
scanf("%lld%lld",&n,&m);
for(int i=1; i<=n; i++)scanf("%lld%lld",&a[i].x,&a[i].t);
sort(a+1,a+n+1,cnt);
for(int i=1,ans2=0; i<=n; i++) {
ans2++;
sum+=a[i].x-a[i-1].x+a[i].t;
int j=i;
while(sum>m) {
sum-=a[j--].t;
ans2--;
}
if(j!=i)
if(sum+a[i].t<=m) {
ans2++;
sum+=a[i].t;
}
ans=max(ans,ans2);
}
printf("%lld",ans);
return 0;
}
求dalao看看 楼主太蒻了