You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
443 B
26 lines
443 B
#include<bits/stdc++.h>
|
|
using namespace std;
|
|
const int N=3e3+5, INF=0x3f3f3f3f;
|
|
int a[N],s[N];
|
|
int main(){
|
|
int n,m;
|
|
cin>>n>>m;
|
|
for(int i=1;i<=n;i++){
|
|
cin>>a[i];
|
|
s[i]=s[i-1]+a[i];
|
|
}
|
|
int ans=INF;
|
|
|
|
//枚举的是区间终点
|
|
//for(int i=m;i<=n;i++) ans=min(ans,s[i]-s[i-m]);
|
|
|
|
//枚举的是区间起点
|
|
for(int i=1;i+m-1<=n;i++){
|
|
int L=i,R=i+m-1;
|
|
ans=min(ans,s[R]-s[L-1]);
|
|
}
|
|
|
|
cout<<ans<<endl;
|
|
return 0;
|
|
}
|