#C3433. Inventory Reorder Decision
Inventory Reorder Decision
Inventory Reorder Decision
You are given an inventory of items, each with a quantity, and a list of sales transactions. For each sale, the quantity of the corresponding item in the inventory is reduced. Your task is to determine which items have a non-positive quantity (i.e., the item needs to be re-ordered) after all sales. If no items need to be re-ordered, output nothing.
The inventory is represented as a list of items. Each item has a name and an available quantity. The sales list consists of transactions that include an item name and the quantity sold.
Mathematically, if an item i has initial quantity \(q_i\) and sales \(s_{ij}\), then the final quantity is given by:
[ q_i^{\prime} = q_i - \sum_{j} s_{ij} ]
An item should be re-ordered if \(q_i^{\prime} \le 0\). The order in which items are output should follow their order of appearance in the inventory input.
inputFormat
The input is read from standard input (stdin) and is formatted as follows:
- The first line contains an integer
n
, the number of items in the inventory. - The next
n
lines each contain an item name (a string without spaces) and an integer representing its quantity, separated by a space. - The next line contains an integer
m
, the number of sales transactions. - The following
m
lines each contain an item name and an integer representing the quantity sold, separated by a space.
You may assume that all item names in the inventory are unique. Sales transactions for items not in the inventory should be ignored.
outputFormat
The output is written to standard output (stdout). Print the names of the items that need to be re-ordered (i.e., items whose final quantity is \(\le 0\)) in their original inventory order, separated by a single space.
If no item needs to be re-ordered, print an empty line.
## sample3
apple 10
banana 5
orange 8
4
apple 4
orange 5
banana 5
apple 6
apple banana