Maximum Average Subsegment
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.
Example 1
5 3 1 2 3 4 5
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
7 2 -1 5 -2 4 0 3 -4
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
# Read the input from stdin and print the answer.
import sys
def main():
data = sys.stdin.read().split()
# your code here
main()
5 3 1 2 3 4 5
7 2 -1 5 -2 4 0 3 -4