AcWing 102. 最佳牛围栏
原题链接
简单
作者:
咕咕_7
,
2021-07-24 23:14:39
,
所有人可见
,
阅读 257
/*
* @Author: your name
* @Date: 2020-10-20 07:19:01
* @LastEditTime: 2021-04-16 18:52:41
* @LastEditors: Please set LastEditors
* @Description: In User Settings Edit
* @FilePath: \vscodecpp\OJ.cpp
*/
#include <iostream>
#include<cstdio>
using namespace std;
const int N=1e5+10;
double a[N],b[N];
int n,f;
bool cmp(double x)
{
for(int i=1;i<=n;i++)
{
b[i]=b[i-1]+(a[i]-x);
}
double Min = 0x3f3f3f3f;
for(int i=f;i<=n;i++)
{
if(b[i-f]<Min)Min=b[i-f];
if(b[i]-Min>0)return true;
}
return false;
}
int main()
{
cin>>n>>f;
for(int i=1;i<=n;i++)scanf("%lf",&a[i]);
double l=1,r=2000;
while(r-l>1e-5)
{
double mid = (l+r)/2;
if(cmp(mid)) l=mid;
else r=mid;
}
cout<<int(r*1000)<<endl;
return 0;
}