#K37057. Potion Quantities Tracking
Potion Quantities Tracking
Potion Quantities Tracking
You are given \(n\) types of potions and an initial amount for each type. You are also provided with \(m\) operations to perform on these potions. Each operation is in the format "op index quantity
", where op
is either add
or remove
, index
(1-indexed) indicates the potion type, and quantity
is the amount to be added or removed.
When processing a remove
operation, only remove the specified quantity if the current number of that potion is at least the quantity to be removed. Otherwise, ignore the operation.
Your task is to simulate these operations and determine the final quantities of each potion.
Note: Input is provided via standard input (stdin) and output should be written to standard output (stdout).
inputFormat
The input is given in the following format:
n m q1 q2 ... qn operation1 operation2 ... operationm
Where:
- \(n\) is the number of potion types.
- \(m\) is the number of operations.
- The second line contains \(n\) integers representing the initial quantities of each potion.
- Each of the next \(m\) lines contains an operation. An operation is a string starting with either
add
orremove
, followed by an index (1-indexed) and the quantity.
outputFormat
Print a single line containing \(n\) integers representing the final quantities of each potion after all operations are executed.
## sample4 5
10 20 30 40
add 2 5
remove 3 10
remove 1 15
add 4 10
remove 2 100
10 25 20 50