#K62927. Warehouse Order Management
Warehouse Order Management
Warehouse Order Management
You are given one or more datasets, each representing the stock of products in a warehouse and a series of customer orders. For each dataset, you must process the orders in the given order and fulfill them according to the available stock. If the ordered quantity exceeds the available stock, supply as much as available (which may be zero) and update the stock accordingly.
The problem can be formulated as follows:
Given an integer (D) denoting the number of datasets. For each dataset:
- An integer (n) is provided, representing the number of stock entries.
- Then (n) lines follow. Each line contains a product code (a string) and an integer representing the stock quantity.
- An integer (m) is provided next, representing the number of orders.
- Then (m) lines follow. Each line contains a product code and an integer representing the order quantity.
For each order, if the product code exists in the current dataset stock:
- If the available stock is at least the order quantity, reduce the stock by the order quantity and output the order with the fulfilled quantity equal to the order quantity.
- Otherwise, supply whatever is available (and reduce the stock to zero) and output the fulfilled quantity.
If the product code does not exist in the stock, output a fulfilled quantity of 0.
Print each result on a new line in the format: "product_code fulfilled_quantity".
For example, if the stock for a product is 50 and an order of 30 is processed, output "product_code 30" and reduce the stock to 20. If a subsequent order for 25 comes in, output "product_code 20" (since only 20 remain) and update the stock to 0.
inputFormat
The input is read from standard input (stdin) and has the following format:
- The first line contains an integer (D), the number of datasets.
- For each dataset:
- A line containing an integer (n), the number of stock items.
- (n) lines follow, each containing a product code and its stock quantity separated by a space.
- A line containing an integer (m), the number of orders.
- (m) lines follow, each containing a product code and an order quantity separated by a space.
outputFormat
For each order processed (in the same order as given in the input), output a line with the product code and the fulfilled quantity separated by a space. The outputs of different datasets are concatenated in the order of appearance.## sample
2
3
PC123 50
PC124 80
PC125 60
4
PC123 30
PC124 100
PC126 10
PC125 45
2
COMP1 100
COMP2 200
3
COMP1 50
COMP3 30
COMP2 250
PC123 30
PC124 80
PC126 0
PC125 45
COMP1 50
COMP3 0
COMP2 200
</p>