RemiliaScar1et @ 2020-04-30 11:19:40
代码如下
#include <bits/stdc++.h>
using namespace std;
int a[200010];
int q[1000010];
int head=1,tail=0;
int dp[1000010];
int n,l,r;
int main()
{
scanf("%d%d%d",&n,&l,&r);
for(int i=0;i<=n;i++)
{
scanf("%d",&a[i]);
}
for(int i=l;i<=n;i++)
{
while(head<=tail&&i-q[head]>r)
{
head++;
}
while(head<=tail&&dp[q[tail]]<=dp[i-l])
{
tail--;
}
q[++tail]=i-l;
dp[i]=dp[q[head]]+a[i];
}
int ans=-10000;
for(int i=n-r+1;i<=n;i++)
{
ans=max(ans,dp[i]);
}
cout<<ans;
return 0;
}
by JROI官方账号 @ 2020-04-30 11:20:11
琪露诺是最强的,告辞(
by RemiliaScar1et @ 2020-04-30 11:24:12
@JROI官方账号
震惊!红萌馆馆主竟被一baka妖精按地暴打,现仍在抢救之中
by NaOH_Frog @ 2020-04-30 11:28:50
@赤红の幼月 琪露诺是最强的,告辞(
by JROI官方账号 @ 2020-04-30 11:32:06
据射命丸文报道,目前事态严峻(雾
by JROI官方账号 @ 2020-04-30 11:35:15
by NaOH_Frog @ 2020-04-30 11:37:41
/fad/jk
by RemiliaScar1et @ 2020-04-30 11:58:18
@JROI官方账号 想起[没有初始化]
by 程义轩 @ 2020-10-24 11:44:52
#include <bits/stdc++.h>
using namespace std;
int a[200005];
int f[200005];
int q[200005], head = 1, tail;
int n, l, r;
int main() {
cin >> n >> l >> r;
for (int i = 0; i <= n; i++) {
cin >> a[i];
}
memset(f, 0xcf, sizeof(f));
int ans = f[0];
f[0] = 0;
int j = 0;
for (int i = l; i <= n; i++) {
while (head <= tail && f[q[tail]] < f[j])
tail--;
q[++tail] = j;
if (q[tail] - q[head] > r - l)
head++;
f[i] = f[q[head]] + a[i];
j++;
}
for (int i = n - r + 1; i <= n; i++) {
ans = max(ans, f[i]);
}
cout << ans << endl;
return 0;
}