求调
查看原帖
求调
558596
TLYK2021001楼主2024/11/21 14:56
#include <bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
int n,l,r,a[300010],head,tail,d[300010];
int q[300010],ans=-inf,num[300010];
int main(){
	scanf("%d%d%d",&n,&l,&r);
	for(int i=0;i<=n;i++)scanf("%d",&a[i]);
	head=tail=1;
	for(int i=l;i<=n;i++){
		while(num[head]<i-r)head++;
		while(head<=tail&&q[tail]<=d[i-l])tail--;
		q[++tail]=d[i-l];
		num[tail]=i-l;
		d[i]=q[head]+a[i];
	} 
	for(int i=n-r+1;i<=n;i++)ans=max(ans,d[i]);
	printf("%d\n",ans);
	return 0;
}
2024/11/21 14:56
加载中...