1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| #include<cstdio> #include<algorithm> using namespace std; typedef long long ll;
const int maxn=200005; int n,h,a[maxn],w[maxn]; int main(){ scanf("%d%d",&n,&h); int s=0; for (int i=1;i<=n;i++){ int l,r;scanf("%d%d",&l,&r); l-=s;r-=s; s+=r-l; a[i]=l;w[i]=r-l; } int ans=0;s=0; for (int i=1,j=1;i<=n;i++){ while (j<=n&&a[j]<a[i]+h) s+=w[j++]; ans=max(ans,s); s-=w[i]; } printf("%d",ans+h); return 0; }
|