SakurajiamaMai @ 2023-05-07 16:12:34
#include<bits/stdc++.h>
using namespace std;
const int N=1000010;
int use[N],l,r,n,hh,tt,q[N],a[N],f[N],res=-1e9;
int main()
{
cin>>n>>l>>r;
for(int i=1;i<=2*n;i++)
f[i]=-2e9;
f[0]=0;
for(int i=l;i<=r;i++) use[i]=1;
for(int i=0;i<=n;i++)
cin>>a[i];
for(int i=0;i<=n;i++)
{
while(hh<=tt&&f[i]>f[q[hh]]) hh++;///队头最大;
while(hh<=tt&&f[i]>f[q[tt]]) tt--;
q[++tt]=i;
f[i+l]=f[q[hh]]+a[i+l];
if(use[i]) use[i+l]=1;
}
for(int i=n+1;i<=n+l;i++)
if(use[i]) res=max(res,f[i]);
cout<<res;
return 0;
}
by progress_from0 @ 2023-06-01 15:41:49
@SakurajiamaMai
while(hh<=tt&& q[hh]+r<i+l ) hh++;///队头最大;
这里出队的条件写错了,不是比f大小,是看是否在转移范围内
by SakurajiamaMai @ 2023-06-03 11:50:19
@progress_from0 谢大佬