Elaina_ @ 2022-11-15 21:28:43
https://www.luogu.com.cn/record/94168860
by 王茗仟 @ 2022-11-15 21:40:15
@Elaina_
可以发一下您的程序嘛
by Elaina_ @ 2022-11-15 21:47:54
@王茗仟
#include<bits/stdc++.h>
using namespace std;
const int F=6000000;
int n,l,r,head,tail,m;
int a[F],bax[F],q1[F],q2[F],f[F];
void work1(){
head=1;
tail=0;
for(int i=1;i<=n;i++){
while(head<=tail&&a[i]>=q1[tail]){
tail--;
}
q1[++tail]=a[i];
q2[tail]=i;
while(head<=tail&&q2[head]<=i-m){
head++;
}
bax[i]=q1[head];
}
}
int main(){
cin>>n>>l>>r;
m=r-l+1;
for(int i=0;i<=n;i++){
cin>>a[i];
}
work1();
for(int i=1;i<=n;i++){
f[i]=-1145141919;
}
for(int i=1;i<=n;i++){
if(i<l){
f[i]=-1145141919;
continue;
}
if(i>=l&&i<=r){
f[i]=a[i];
continue;
}
f[i]=max(f[i-l]+a[i],f[i]);
}
int out=-1145141919;
for(int i=n;i>=n-r+1;i--){
if(out<f[i]){
out=f[i];
}
}
cout<<out;
return 0;
}
已经找到问题了,正在改