Accepted
代码
#include <iostream>
#include <cstring>
#include <string>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
using namespace std;
int st,ed,n,sum[500001],ans=-2147483647,l=1,r=0,q[500001],x;
int main()
{
scanf("%d%d%d",&n,&st,&ed);
for(int i=1;i<=n;i++)scanf("%d",&x),sum[i]=sum[i-1]+x;
q[r]=0;
for(int i=st;i<=n;i++)
{
while(r>=l&&i-q[l]>ed)l++;
while(r>=l&&sum[q[r]]>=sum[i-st])r--;
q[++r]=i-st;
ans=max(ans,sum[i]-sum[q[l]]);
}
printf("%d",ans);
return 0;
}