https://www.luogu.org/problemnew/show/P1725
#include <iostream>
#include <cstdio>
using namespace std;
const int MAXN=800005,inf=1000000000;
int n,l,r,top,a[MAXN],f[MAXN],h=1,t=1,ans,q[MAXN];
int main(){
scanf("%d%d%d",&n,&l,&r);q[1]=0;
for(int i=1;i<=n+1;i++) scanf("%d",&a[i-1]);
for(int i=l;i<=n+r;i++){
while(h<=t && f[i-l]>=f[q[t]]) t--; q[++t]=i-l;
while(h<=t && q[h]<i-r) h++;
f[i]=f[q[h]]+a[i];
}
for(int i=n+1;i<=n+r;i++)
ans=max(ans,f[i]);
printf("%d\n",ans);
return 0;
}