codeforces 1003c

#include <iostream>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long ll;
char str[]="01";
int sum[5007];
int a[5004];
int main()
{

        int n,k;
        double average;
        double maxx=-0x3f3f3f;
        cin>>n>>k;
        for(int i=1;i<=n;i++)
        {
            cin>>a[i];
        }
        for(int i=1;i<=n;i++)
            sum[i]=sum[i-1]+a[i];
        for(int i=1;i<=n;i++)
        {
            for(int j=i+k-1;j<=n;j++)
            {
                average=((double)sum[j]-(double)(sum[i-1]))/(double)(j-i+1);
                if(maxx<average)
                    maxx=average;
            }
        }
        printf("%lf\n",maxx);

    return 0;
}

 

点赞