#C990. Stock Price Monitor

    ID: 54044 Type: Default 1000ms 256MiB

Stock Price Monitor

Stock Price Monitor

In this problem, you are required to simulate a stock price monitoring system using a sliding window. The system maintains the last (K) stock prices and supports two types of operations:

  1. add x: Adds a new stock price (x) (an integer) to the system.
  2. average: Computes and prints the average of the last (K) stock prices. If fewer than (K) prices have been added so far, the average is computed using all the received prices. The result must be displayed with exactly 2 decimal places.

The input is read from standard input (stdin) and the output should be written to standard output (stdout). Ensure careful handling of the sliding window and proper formatting of the average value.

inputFormat

The first line contains an integer (K) representing the size of the sliding window. The second line contains an integer (N) representing the number of operations. The following (N) lines each contain an operation in one of the following formats:

add x - where x is an integer representing the new stock price to add. • average - to query the current sliding window average.

It is guaranteed that all inputs are valid.

outputFormat

For each average operation, print the computed average on a new line with exactly 2 decimal places.## sample

3
10
add 10
average
add 20
average
add 30
average
add 40
average
add 50
average
10.00

15.00 20.00 30.00 40.00

</p>