#K73112. Moving Average Calculation
Moving Average Calculation
Moving Average Calculation
You are given two integers (N) and (M), where (N) represents the maximum number of latest prices to consider, and (M) represents the total number of stock price entries. Then you are given (M) stock prices. Your task is to compute the moving average over a sliding window that contains at most (N) most recent prices. For each new price, print the average of the current window with exactly one digit after the decimal point. This simulates a real-time price analysis found in stock trading systems.
inputFormat
The input is given via standard input (stdin). The first line contains two space-separated integers (N) and (M). The second line contains (M) space-separated integers representing the stock prices.
outputFormat
For each of the (M) stock prices, output a line containing the moving average of the last at most (N) prices, formatted to one decimal place. Output must be written to standard output (stdout).## sample
3 5
10 20 30 40 50
10.0
15.0
20.0
30.0
40.0
</p>