#C5809. Warehouse Inventory Management
Warehouse Inventory Management
Warehouse Inventory Management
You are given an inventory management system for a warehouse. The system processes a sequence of operations to manage the stocks of various items.
There are three types of operations:
receive k x
: Increases the inventory of itemx
by an integer k.dispatch k x
: Decreases the inventory of itemx
by an integer k if the current stock is at least k. Otherwise, the operation is ignored.check x
: Outputs the current inventory count for itemx
.
The input begins with an integer representing the number of operations. Each of the subsequent lines contains one operation. For each check
operation, you should print the current inventory count for the item on a separate line.
Note: All formulas, such as the quantity k, should be interpreted in the usual way. For example, if you see an operation receive 10 apples
, then the inventory of apples increases by \(10\).
inputFormat
The first line contains an integer \(N\) representing the number of operations. Each of the next \(N\) lines contains an operation in one of the following formats:
receive k x
— add \(k\) items of type \(x\) to inventory.dispatch k x
— remove \(k\) items of type \(x\) if available.check x
— output the current number of item \(x\) in the inventory.
Input is provided via standard input (stdin).
outputFormat
For each check
operation in the input, output the inventory count for the specified item on a new line. The output should be printed to standard output (stdout).
8
receive 10 apples
receive 5 bananas
dispatch 2 apples
check apples
check bananas
check oranges
dispatch 3 bananas
check bananas
8
5
0
2
</p>