http://www.elijahqi.win/archives/3919
暴力枚举
枚举长度再枚举区间 枚举区间的时候只需要删除后面的添加前面的即可
#include<bits/stdc++.h>
using namespace std;
inline char gc(){
static char now[1<<16],*S,*T;
if (T==S){T=(S=now)+fread(now,1,1<<16,stdin);if (T==S) return EOF;}
return *S++;
}
inline int read(){
int x=0,f=1;char ch=gc();
while(!isdigit(ch)) {if (ch=='-') f=-1;ch=gc();}
while(isdigit(ch)) {x=x*10+ch-'0',ch=gc();}
return x*f;
}
const int N=5500;
int n,k,a[N];double sum,ans;
int main(){
// freopen("c.in","r",stdin);
n=read();k=read();
for (int i=1;i<=n;++i) a[i]=read();
for (int l=k;l<=n;++l){
sum=0;
for (int i=1;i<=l;++i) sum+=a[i];
ans=max(ans,sum/l);
for (int i=l+1;i<=n;++i){
sum-=a[i-l];sum+=a[i];
ans=max(ans,sum/l);
}
}printf("%.10f\n",ans);
return 0;
}