暴力求长度为L的子段的最大平均数都77分,数据有点水吧

P10450 [USACO03MAR] Best Cow Fences G

yibin @ 2024-10-04 20:56:24

#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#define ll long long
using namespace std;
const int Inf=1e5+1;
int  n,l;
ll sum[Inf];
ll a[Inf];
void Int(){
    scanf("%d%d",&n,&l);
    for(int i=1;i<=n;i++)
    {
        scanf("%lld",&a[i]);
        a[i]*=1000;
        sum[i]=sum[i-1]+a[i];
    }
    ll ans=0;
    for(int i=l;i<=n;i++){
        ans=max(ans,(sum[i]-sum[i-l])/l);
    }
    printf("%lld",ans);
}
signed main(){
    int t=1;
    while(t--)Int();
    return 0;
}

by Fractured_Angel @ 2024-10-04 21:19:55

那确实有点水。。。


|