#K91397. Efficient Inventory Update Using Difference Array
Efficient Inventory Update Using Difference Array
Efficient Inventory Update Using Difference Array
You are given an integer \( n \) representing the number of products and an array of \( n \) integers representing the initial inventory levels. In addition, you are provided with \( m \) operations. Each operation is given as three integers \( l \), \( r \), and \( v \) which means that for every product from index \( l \) to \( r \) (inclusive, 1-indexed) you need to update the inventory by adding \( v \).
You must update the inventory efficiently and output the final inventory levels.
Example:
Input: 6 10 20 30 40 50 60 3 1 3 10 4 6 -20 2 5 5</p>Output: 20 35 45 25 35 40
inputFormat
The input is given via standard input (stdin) and is formatted as follows:
- The first line contains a single integer \( n \), the number of products.
- The second line contains \( n \) space-separated integers representing the initial inventory levels.
- The third line contains a single integer \( m \), the number of operations.
- The next \( m \) lines each contain three space-separated integers \( l \), \( r \), and \( v \) representing an operation.
outputFormat
The output should be printed to standard output (stdout) as a single line of \( n \) space-separated integers representing the final inventory levels after all operations.
## sample6
10 20 30 40 50 60
3
1 3 10
4 6 -20
2 5 5
20 35 45 25 35 40