社区讨论
100pts求助
P1725琪露诺参与者 2已保存回复 3
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 3 条
- 当前快照
- 1 份
- 快照标识符
- @miv411u8
- 此快照首次捕获于
- 2025/12/07 10:35 2 个月前
- 此快照最后确认于
- 2025/12/09 21:05 2 个月前
CPP
#include<bits/stdc++.h>
using namespace std;
const int N=2e3+5;
const int M=2e5+5;
const int Mod=1e9+7;
int st[500005][20];
int q[500005];
int a[500005];
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
//Write the code here
//Come
int n,m;
cin>>n>>m;
for(int i=1;i<=n;i++){
cin>>a[i];
q[i]=q[i-1]+a[i];
st[i][0]=q[i];
}
int l=log2(n);
for(int j=1;j<=l;j++){
for(int i=1;i<=n-(1<<j)+1;i++){
st[i][j]=min(st[i][j-1],st[i+(1<<(j-1))][j-1]);
}
}
int ans=INT_MIN;
for(int i=1;i<=n;i++){
int l=i-m;
if(l<0)l=0;
int k=log2(i-l+1);
int mn=min(st[l][k],st[i-(1<<k)+1][k]);
ans=max(ans,q[i]-mn);
}
if(ans==0)cout<<-1;
else cout<<ans;
return 0;
}
//LMAO
//Code by chc
回复
共 3 条回复,欢迎继续交流。
正在加载回复...