30分,求助

P10450 [USACO03MAR] Best Cow Fences G

yujincheng @ 2025-01-11 11:08:12

#include <bits/stdc++.h>
using namespace std;
int n,len,l,r;
int a[100005],sum[100005];
long double ans;
int main()
{
    cin>>n>>len;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    for(int i=1;i<=n;i++)
        sum[i]=a[i]+sum[i-1];
    for(int i=len;i<=n;i++)
    {
        l=1,r=i;
        while(1)
            if(r==n)
                break;
            else if(a[r+1]>=a[l])
                l++,r++;
            else
                break;
        ans=max(ans,(long double)(int((sum[r]-sum[l-1])*1000.0/i)));
    }
    cout<<ans;
    return 0;
}

by yujincheng @ 2025-01-11 15:45:53

ooo,wssb.


|