#K93212. Moving Average of Array
Moving Average of Array
Moving Average of Array
Given an array of integers and a window size \(k\), your task is to compute the moving average of every contiguous subarray of length \(k\). The moving average for a window starting at index \(i\) is defined as:
\(average_i = \frac{1}{k} \sum_{j=i}^{i+k-1} a_j\)
If \(k > n\) where \(n\) is the number of elements in the array, then there is no valid window and no output should be produced.
All answers must round the result to two decimal places.
inputFormat
Input is read from standard input (stdin).\nThe first line contains two integers (n) and (k) separated by a space, where (n) is the number of elements in the array and (k) is the window size.\nThe second line contains (n) space-separated integers representing the array.
outputFormat
Output the moving averages for all contiguous subarrays of length (k) in one line, separated by a single space. Each average must be rounded to two decimal places. If no valid window exists, produce no output.## sample
8 3
10 20 30 40 50 60 70 80
20.00 30.00 40.00 50.00 60.00 70.00