#K3116. Inventory System Simulation

    ID: 24888 Type: Default 1000ms 256MiB

Inventory System Simulation

Inventory System Simulation

You are required to implement an inventory system that supports adding, removing, and updating products as well as calculating the total weight of all products in stock. The system will process a series of commands provided via standard input. The supported commands are as follows:

1. Add Product: Format: 1 product_id weight count – Adds a new product with the given ID, weight, and count.
2. Remove Product: Format: 2 product_id – Removes the product with the specified ID from the inventory.
3. Update Product Count: Format: 3 product_id count – Updates the count for the specified product.
4. Calculate Total Weight: Format: 4 – Calculates and outputs the total weight of all products currently in stock. The total weight is computed using the formula
(\text{Total Weight} = \sum (\text{weight} \times \text{count})).

Whenever a command of type 4 is encountered, you must immediately output the total weight as a floating point number on a new line.

inputFormat

The first line of input contains an integer Q, the number of commands. The next Q lines each contain one command. Commands are in one of the following formats:

- 1 product_id weight count (to add a product)
- 2 product_id (to remove a product)
- 3 product_id count (to update a product's count)
- 4 (to output the total weight)

outputFormat

For every command of type 4, output the total weight of the products currently in the system as a floating point number. Each output must be printed on a new line.## sample

4
1 1 2.5 10
4
25.0

</p>