92pts 求条

P10450 [USACO03MAR] Best Cow Fences G

dg114514 @ 2024-11-15 17:07:17

#include<bits/stdc++.h>
#define int long long
using namespace std;
constexpr int N=1e5+10;
double l=1,r=3e5,mid,sum[N],a[N];
int n,k;
int check(double x){
    for(int i=1;i<=n;i++)sum[i]=sum[i-1]+a[i]-x;
    double mi=1e10;
    for(int i=k;i<=n;i++)
        if(sum[i]-(mi=min(mi,sum[i-k]))>=0)
            return true;
    return false;
}
signed main(){
    cin>>n>>k;
    for(int i=1;i<=n;i++)cin>>a[i];
    while(r-l>1e-5){
        mid=(l+r)/2;
        if(check(mid))l=mid;
        else r=mid;
    }
    cout<<(int)(r*1000);
}

|