#K57077. Inventory Update Challenge
Inventory Update Challenge
Inventory Update Challenge
You are given an inventory list with n items. Each item in the inventory is represented by its name and available quantity. You are also given m orders. Each order specifies an item name and an order quantity. For each order, update the inventory as follows: if the order quantity exceeds the current stock, the item’s stock becomes 0; otherwise, subtract the order quantity from the current stock. If an order references an item not in the inventory, ignore it.
The updated inventory should be reported in the same order as the original inventory list.
Formally, for an item with initial quantity \(q\) and an order of quantity \(x\), the new quantity \(q_{new}\) is given by:
$$ q_{new} = \max(q - x, 0) $$If there are multiple orders for the same item, process them in the order they appear.
inputFormat
The first line contains an integer n, the number of items in the inventory.
The following n lines each contain an item name (a string) and its quantity (an integer), separated by a space.
The next line contains an integer m, the number of orders.
The following m lines each contain an item name (a string) and an order quantity (an integer), separated by a space.
outputFormat
For each inventory item in the original order, output a line containing the item name and its updated quantity, separated by a space.
## sample4
apple 50
banana 30
orange 20
grape 10
3
apple 60
banana 10
grape 5
apple 0
banana 20
orange 20
grape 5
</p>