#C9241. Inventory Update Challenge
Inventory Update Challenge
Inventory Update Challenge
You are given an inventory of products and a series of quantity changes. Your task is to update the inventory by applying the given changes. For each product code in the inventory, update its quantity using the formula:
\( \text{new_quantity} = \max(\text{current_quantity} + \text{quantity_change}, 0) \)
If a product code from the changes is not present in the inventory, ignore that change. The order of the products in the output should be the same as the input order.
inputFormat
The input is read from standard input and has the following format:
- An integer \(n\) representing the number of products in the inventory.
- \(n\) lines follow, each containing a product code (a string) and an integer indicating the current quantity, separated by a space.
- An integer \(m\) representing the number of changes.
- \(m\) lines follow, each containing a product code and an integer representing the quantity change, separated by a space.
outputFormat
The output is written to standard output. For each of the \(n\) products (in the order given in the input), print a line with the product code and its updated quantity (separated by a space).
## sample3
A123 10
B456 5
C789 0
3
A123 -2
B456 3
C789 5
A123 8
B456 8
C789 5
</p>