#K93632. Storage Unit Operations
Storage Unit Operations
Storage Unit Operations
You are given \(P\) storage units. Each storage unit initially contains a certain number of items. You will then receive \(Q\) operations to perform on these storage units. Each operation is represented by three integers: operation_type
, unit_index
, and items
.
If operation_type = 1
, add items
to the storage unit at index unit_index
; if operation_type = 2
, remove items
from the storage unit at index unit_index
. Note that the number of items in any storage unit cannot fall below zero. In mathematical terms, when performing a removal, the new count is given by:
\[
storage[unit_index] = \max(0, storage[unit_index] - items)
\]
Indices are 0-based.
Your task is to compute and output the final number of items in each storage unit after processing all operations.
inputFormat
The input is read from standard input (stdin) as follows:
- The first line contains an integer \(P\) representing the number of storage units.
- The second line contains \(P\) space-separated integers, where the \(i^{th}\) integer is the initial number of items in the \(i^{th}\) storage unit.
- The third line contains an integer \(Q\) representing the number of operations.
- Each of the next \(Q\) lines contains three integers:
operation_type
,unit_index
, anditems
.
outputFormat
Print a single line to standard output (stdout) containing \(P\) space-separated integers. Each integer represents the final number of items in the corresponding storage unit after all operations have been performed.
## sample5
10 20 30 40 50
4
1 1 5
2 3 10
1 4 15
2 2 35
10 25 0 30 65