1 条题解
-
0
// 单调队列+DP O(n) #include<bits/stdc++.h> using namespace std; const int N=200010; int n,L,R; int a[N],f[N],q[N]; int main(){ scanf("%d%d%d",&n,&L,&R); for(int i=0;i<=n;i++) scanf("%d",&a[i]); memset(f,-0x3f,sizeof f); f[0]=0; int ans=-2e9; for(int i=L,h=1,t=0;i<=n;i++){ while(h<=t && q[h]<i-R) h++; while(h<=t && f[q[t]]<=f[i-L]) t--; q[++t]=i-L; f[i]=f[q[h]]+a[i]; if(i>n-R) ans=max(ans,f[i]); } printf("%d\n",ans); }
- 1
信息
- ID
- 1874
- 时间
- 1000ms
- 内存
- 512MiB
- 难度
- 8
- 标签
- 递交数
- 37
- 已通过
- 6
- 上传者
