#K12896. Warehouse Inventory Management
Warehouse Inventory Management
Warehouse Inventory Management
You are given a task to implement a Warehouse system which manages an inventory of items. The warehouse supports the following operations:
- add i q: Add q quantity of item with id i to the warehouse.
- remove i q: Remove q quantity of item with id i from the warehouse. This operation is executed only if the current quantity for the item is greater than or equal to q. If the removal causes the quantity to become 0, the item is removed from the inventory.
- count i: Output the current quantity of item with id i in the warehouse. If the item does not exist, output 0.
- unique: Output the total number of unique items currently in the warehouse (items with a non-zero quantity).
- total: Output the total sum of quantities of all items in the warehouse.
For example, if you add 50 units of item 1 and 30 units of item 2, a subsequent query count 1
should output 50. If you remove 10 units from item 1, then count 1
should output 40. If you try to remove more units than available, the operation should be ignored.
Note: All formulas or numbers must be displayed using LaTeX format where applicable (e.g. when referring to quantities, one may write \(q\)).
inputFormat
The first line of input contains a single integer \(n\) which denotes the number of operations to be performed. The following \(n\) lines each contain one of the following operations:
add i q
— add \(q\) quantity of item with id \(i\).remove i q
— remove \(q\) quantity of item with id \(i\) if possible.count i
— print the current quantity of item with id \(i\).unique
— print the number of unique items in the inventory.total
— print the total quantity of all items in the inventory.
Each operation is given on a separate line via standard input (stdin).
outputFormat
For every operation that requires an output (count
, unique
, and total
), print the corresponding integer on a separate line to standard output (stdout).
7
add 1 50
add 2 30
count 1
remove 1 10
count 1
unique
total
50
40
2
70
</p>