#C8191. Inventory Report Processing
Inventory Report Processing
Inventory Report Processing
You are given a series of inventory operations for products. Each operation is either "add" or "remove". For each operation, you are provided with a product id and a quantity. Your task is to process these operations and compute the final quantity of each product. Finally, output the product ids and their corresponding final quantities in ascending order of the product ids.
The input is given via standard input (stdin) and the output should be printed to standard output (stdout). Each product id and final quantity should be printed on a separate line separated by a space.
Note: The operations are defined by the following formula: \[ \text{Final Quantity} = \sum_{i=1}^{M} \begin{cases} +q_i & \text{if operation is add} \\ -q_i & \text{if operation is remove} \end{cases} \] where \(M\) is the total number of operations, and \(q_i\) is the quantity associated with the \(i^{th}\) operation.
inputFormat
The first line contains a single integer \(M\) representing the number of operations. The following \(M\) lines each contain an operation in the format:
operation product_id quantity
where:
operation
is eitheradd
orremove
.product_id
is an integer identifying the product.quantity
is an integer representing how much to add or remove.
outputFormat
For each unique product id that appears in the input, output a line with the product id and its final quantity separated by a space. The output should be sorted in ascending order according to the product id.
## sample5
add 1 100
remove 2 50
add 2 70
add 1 30
remove 1 10
1 120
2 20
</p>