#K11086. Warehouse Inventory Management
Warehouse Inventory Management
Warehouse Inventory Management
You are required to implement a warehouse management system. The system is initialized with a list of shelves, each containing a certain number of items. You need to process a sequence of operations on the warehouse. There are three types of operations:
- Add Operation (Type 1): Add a certain number of items to a specified shelf.
- Remove Operation (Type 2): Remove a certain number of items from a specified shelf. Note that you can only remove as many items as are available on that shelf. In other words, if the shelf has fewer items than the number to be removed, remove all the remaining items.
- Total Query (Type 3): Output the total number of items across all shelves.
The shelves are 1-indexed. The total number of items across all shelves can be expressed as follows:
\[ T = \sum_{i=1}^{n} a_i \]where \(a_i\) is the number of items on the \(i^{th}\) shelf.
Make sure your program reads from stdin
and writes to stdout
.
inputFormat
The first line contains two integers n and m separated by a space where n is the number of shelves and m is the number of operations.
The second line contains n integers separated by spaces representing the initial number of items on each shelf.
The next m lines describe the operations. Each operation is in one of the following formats:
- For Add:
1 shelf_id count
- For Remove:
2 shelf_id count
- For Total Query:
3
Note: For Add and Remove operations, shelf_id
is 1-indexed.
outputFormat
For each Total Query (operation type 3), output a single line containing the total number of items across all shelves.
## sample3 3
10 20 30
1 1 5
2 2 15
3
50
</p>