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
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
2
10 6
6
4
2
10
3
8
5
9
4
1
5 2
10
3
8
5
9
6500
7333
比赛时这道题坑死,热身赛时听学长们说的TLE不提醒,一直以为是超时了。最后才发现不需要四舍五入。。。
#include <cstdio> #include <cstring> #include <algorithm> #define MAX 4000000+10 using namespace std; int a[2010]; int aver[MAX]; int main() { int t; int n, m; int i, j, k, l; int sum = 0; scanf("%d", &t); while(t--) { scanf("%d%d", &n, &m); for(i = 1; i <= n; i++) scanf("%d", &a[i]); k= 0; for(i = 1; i <= n; i++) { for(l = m; l <= n; l++) { if(i + l > n+1) break; sum = 0; for(j = i; j < i+l; j++) { sum += a[j]; } aver[k++] = sum *1000 / l; } } sort(aver, aver+k); printf("%d\n", aver[k-1]); } return 0; }