没有被hack,因为前面一段不是预处理的,不会出现跑不到的点dp有值的情况
#include<cstdio>
#include<cstring>
#include<deque>
#include<cstdlib>
#define MAXN 200005
inline int max(int x,int y){return x>y?x:y;}
int n,l,r,ans,a[MAXN],dp[MAXN];
std::deque<int> q;
int main(){
memset(dp,-0x3f,sizeof(dp));
scanf("%d%d%d",&n,&l,&r);
for(int i=0;i<=n;i++){
scanf("%d",&a[i]);
}
q.push_back(0);dp[0]=0;
for(int i=l;i<=n;i++){
while(!q.empty()&&dp[q.back()]<dp[i-l])q.pop_back();
q.push_back(i-l);//先入队
while(!q.empty()&&q.front()<i-r)q.pop_front();
int u=q.front();
dp[i]=dp[u]+a[i];
// printf("%d %d %d
",u,i,dp[i]);
}
for(int i=n-r+1;i<=n;i++)ans=max(ans,dp[i]);
printf("%d
",ans);
}
写的真丑,但是真的短
话说这题为什么是绿题啊,明明修剪草坪都是蓝