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 maximum average strength, given the constraint.

输入
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
输出
For each test case generate a single line containing a single integer that is 1000 times the maximal average value. Do not perform rounding.
样例输入
2 10 66 42103859415 210385 9 
样例输出

65007333


#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int ans[2005];
int main(){
	int t,n,m;
	cin >>t;
	while(t--){
		cin >>n>>m;
		memset(ans,0,sizeof(ans));
		ans[0]=0;
		for(int i=1;i<=n;i++){
			int x;
			scanf("%d",&x);
			ans[i]=ans[i-1]+x;
		}
		double sum=0;
		for(int i=1;i<=n;i++){
			for(int j=i+m-1;j<=n;j++){
				double temp=((ans[j]-ans[i-1])*1.0/(j-i+1));
				sum=max(sum,temp);
			}
		}
		int kk=(int)(sum*1000);
		printf("%d\n",kk);
	}
	return 0;
}


你可能感兴趣的:(水题)