#K46632. Maximum Average Subarray

    ID: 28020 Type: Default 1000ms 256MiB

Maximum Average Subarray

Maximum Average Subarray

Given an integer array and an integer k, your task is to compute the maximum average of any contiguous subarray of length k. Formally, if the array is \(a_1, a_2, \dots, a_n\), you are to find the maximum value of \(\frac{a_i+a_{i+1}+\cdots+a_{i+k-1}}{k}\) for \(1 \leq i \leq n-k+1\). It is guaranteed that \(k \leq n\).

The computation should be performed efficiently using a sliding window approach. The answer is expected as a floating point number exactly matching the samples.

inputFormat

The input is read from stdin and consists of two lines. The first line contains two integers: n (the number of elements in the array) and k (the length of the subarray to consider), separated by a space. The second line contains n space-separated integers representing the array.

For example:

6 4
1 12 -5 -6 50 3

outputFormat

Output the maximum average of any contiguous subarray of length k to stdout as a floating point number. The output should match the examples exactly.

For the input above, the output would be:

12.75
## sample
6 4
1 12 -5 -6 50 3
12.75