G. Interference Signal
Dr.Kong’s laboratory monitor some interference signals. The interference signals can be digitized into a series of positive integer. May be, there are N integers a1,a2,…,an.
Dr.Kong wants to know the average strength of a contiguous interference signal block. the block must contain at least M integers.
Please help Dr.Kong to calculate the max i mum average strength, given the constraint.
Input
The input contains K test cases. Each test case specifies:
* Line 1: Two space-separated integers, N and M.
* Lines2~line N+1: ai (i=1,2,…,N)
1 ≤ K≤ 8, 5 ≤ N≤ 2000, 1 ≤ M ≤ N, 0 ≤ ai ≤9999
* Line 1: Two space-separated integers, N and M.
* Lines2~line N+1: ai (i=1,2,…,N)
1 ≤ K≤ 8, 5 ≤ N≤ 2000, 1 ≤ M ≤ N, 0 ≤ ai ≤9999
Output
For each test case generate a single line containing a single integer that is 1000 times the maximal average value. Do not perform rounding.
Sample Input
2 10 6 6 4 2 10 3 8 5 9 4 1 5 2 10 3 8 5 9
Sample Output
6500 7333
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int maxn=2009;
long long a[maxn];
int main()
{
int t;
int k;
int n;
scanf("%d",&t);
while(t--)
{
memset(a,0,sizeof(a));
scanf("%d%d",&n,&k);
for(int i=1;i<=n;i++)
{
scanf("%lld",&a[i]);
a[i]+=a[i-1];
}
double ave=0;double maxx=0;
for(int i=0;i<=n;i++)
{
for(int j=n;j>=1;j--)
{
if(j-i<k) break;
ave=(double)(a[j]-a[i])/(j-i);
maxx=max(ave,maxx);
}
}
long long ans=(long long)(maxx*1000);
printf("%lld\n",ans);
}
return 0;
}