前置问题是最长子段
#include<bits/stdc++.h>
using namespace std;
double a[100010],b[100010],sum[100010];//b数组用于记录牛的数量与mid的差值
int main()
{
int n,f;
cin >> n >> f;
for(int i = 1;i <= n;++i){
cin >> a[i];
}
double mid;
double l = -1e6,r = 1e6;
double esp = 1e-6;//精度
while(r - l > esp)
{
double mid = (l + r) / 2;
for(int i = 1;i <= n;++i) b[i] = a[i] - mid;
for(int i = 1;i <= n;++i){
sum[i] = (sum[i - 1] + b[i]);
}
double ans = -1e10;
double min_val = 1e10;
for(int i = f;i <= n;++i){
min_val = min(min_val,sum[i - f]);
ans = max(ans,sum[i] - min_val);
}
if(ans >= 0) l = mid;
else r = mid;
}
cout << int(r * 1000) << endl;
}