#K81677. Warehouse Inventory Management System
Warehouse Inventory Management System
Warehouse Inventory Management System
This problem simulates a warehouse inventory management system. The system supports three types of operations:
- ADD id v: Increase the inventory of product id by v units.
- REMOVE id v: Decrease the inventory of product id by v units. The inventory will not go below 0.
- QUERY id: Output the current inventory level for product id.
Formally, if we denote \(inv[id]\) as the inventory for product \(id\), the operations are defined as:
[ \begin{aligned} \text{ADD}:\quad & inv[id] \leftarrow inv[id] + v, \ \text{REMOVE}:\quad & inv[id] \leftarrow \max(0, inv[id] - v), \ \text{QUERY}:\quad & \text{output } inv[id]. \end{aligned} ]
You are given a series of queries. Process them in the order given and for every QUERY command, print the current inventory value for the given product.
inputFormat
The input is read from standard input (stdin) and has the following format:
Q query_1 query_2 ... query_Q
Here, Q is the number of queries. Each of the following Q lines is in one of the following formats:
- ADD id v
- REMOVE id v
- QUERY id
All parameters are integers.
outputFormat
For every QUERY operation, output the current inventory level of the specified product on a new line to standard output (stdout).
## sample6
ADD 1 100
ADD 2 150
REMOVE 1 50
QUERY 1
ADD 1 30
QUERY 1
50
80
</p>