#C6242. Sliding Window Maximum Average
Sliding Window Maximum Average
Sliding Window Maximum Average
You are given T test cases. For each test case, you will be provided with two integers n and k followed by n integer values representing the grades of students. Your task is to find the highest average of any contiguous subarray of length k in the list of grades.
More formally, for each test case, you need to determine the maximum sum of any k consecutive grades, then compute the average by dividing this sum by k. The result should be printed with exactly two decimal places.
Note: Use the sliding window technique to achieve an efficient solution.
The mathematical formulation for the average is given by:
\(\text{Maximum Average} = \frac{\max_{0 \leq i \leq n-k}\left(\sum_{j=i}^{i+k-1} a_j\right)}{k}\)
inputFormat
The first line of input contains a single integer T (1 ≤ T ≤ 100), representing the number of test cases. For each test case:
- The first line contains two space-separated integers n and k (1 ≤ k ≤ n ≤ 105), where n is the number of grades and k is the length of the subarray.
- The second line contains n space-separated integers representing the grades. Each grade can be assumed to be in the range [1, 109].
Input is provided via standard input (stdin).
outputFormat
For each test case, print a single line containing the maximum average of any contiguous subarray of length k, formatted with two decimal places. Output should be written to standard output (stdout).
## sample1
8 3
5 12 11 5 7 16 19 3
14.00
</p>