#C11736. Moving Average from Data Stream

    ID: 41085 Type: Default 1000ms 256MiB

Moving Average from Data Stream

Moving Average from Data Stream

You are given a window size \(w\) and a stream of \(n\) integers. Your task is to compute the moving average of the last \(w\) numbers in the stream after each new integer is received. If fewer than \(w\) numbers have been received, compute the average of all numbers received so far.

For example, if \(w = 3\) and the stream is: 1, 10, 3, 5, then the moving averages are computed as follows:

  • After receiving 1, average = \(1.000000\)
  • After receiving 10, average = \(\frac{1+10}{2} = 5.500000\)
  • After receiving 3, average = \(\frac{1+10+3}{3} = 4.666667\)
  • After receiving 5, since the window contains the last three elements (10, 3, 5), average = \(\frac{10+3+5}{3} = 6.000000\)

Your program should read the input from stdin and produce the output to stdout.

inputFormat

The first line of the input contains two integers: \(w\) (the window size) and \(n\) (the number of elements in the stream), separated by a space. The second line contains \(n\) integers, representing the stream values, separated by spaces.

Constraints:

  • \(1 \leq w \leq n \leq 10^5\)
  • Each integer in the stream is between \(-10^9\) and \(10^9\) (inclusive).

outputFormat

Output \(n\) lines. Each line contains the moving average after reading the respective integer from the stream. The average should be printed as a floating-point number with 6 decimal places.

## sample
3 4
1 10 3 5
1.000000

5.500000 4.666667 6.000000

</p>