Maximum Average SubsegmentMedium

Maximum Average Subsegment

MediumPractice library · +20 XPbinary searchprefix sumsarrays

Given an array A of N integers, find a subsegment (contiguous subarray) of length at least K such that the average of its elements is maximized. Print the maximum possible average.

Input

The first line contains two integers N and K. The second line contains N integers of the array A.

Output

Print a single floating-point number representing the maximum possible average. The answer must be accurate to at least 6 decimal places.

Constraints

1 <= K <= N <= 200000. -10^9 <= A[i] <= 10^9. The sum of N over all test cases does not exceed 200000.

Time limit 2 s (native code; slower languages get more)Memory 256 MB15 hidden tests

Example 1

Input
5 3
1 2 3 4 5
Output
4.0000000

The subsegment [3, 4, 5] has length 3 and average (3+4+5)/3 = 4.0. Any longer subsegment will have a larger average. For example, [1,2,3,4,5] has average 3.0.

Example 2

Input
7 2
-1 5 -2 4 0 3 -4
Output
2.3333333

The subsegment [5, -2, 4, 0, 3] has length 5 and average (5-2+4+0+3)/5 = 10/5 = 2.0. However, the subsegment [5, -2, 4] has average (5-2+4)/3 = 7/3 approx 2.33. The subsegment [5] is length 1 and invalid. The subsegment [5, -2] has average 1.5. The subsegment [4, 0, 3] has average 7/3 approx 2.33. T

Hints