#K52852. Adjust the Warehouses
Adjust the Warehouses
Adjust the Warehouses
You are given N warehouses, each containing an initial number of items. Then, M instructions are provided to adjust the item counts in these warehouses. Each instruction is of one of the two types:
add
: Adds a specified number of items to a given warehouse.remove
: Removes a specified number of items from a given warehouse, but the number of items cannot drop below 0. Formally, if a warehouse hasx
items andv
items are removed, the new count is \(\max\{x - v, 0\}\).
Your task is to compute the final number of items in each warehouse after applying all instructions sequentially.
inputFormat
The input is read from stdin and has the following format:
N M initial_item_1 initial_item_2 ... initial_item_N instruction_1 instruction_2 ... instruction_M
Here:
N
is the number of warehouses.M
is the number of instructions.- The next line provides
N
integers, where theith
integer is the initial number of items in theith
warehouse. - Each instruction is provided on a new line and consists of a string and two integers separated by spaces. The string is either
add
orremove
, the first integer is the 1-indexed warehouse number, and the second integer is the number of items to add or remove.
outputFormat
The output should be written to stdout as a single line containing N
integers separated by spaces. Each integer represents the final number of items in the corresponding warehouse after processing all instructions.
4 3
100 200 300 400
add 2 50
remove 3 100
remove 1 150
0 250 200 400