#C8459. Apply Operations and Sum

    ID: 52443 Type: Default 1000ms 256MiB

Apply Operations and Sum

Apply Operations and Sum

You are given an array \(A\) of \(n\) integers and \(m\) operations. Each operation is described by three integers \(l\), \(r\) and \(v\). For every operation, you need to add \(v\) to every element in the subarray from index \(l\) to index \(r\) (inclusive). An extra integer \(k\) is provided but is not used in this problem (it may be useful for future variations).

After performing all the operations sequentially, output the sum of the modified array. The indices are 0-indexed.

Note: The formula for the update of an element \(A_i\) in an operation is given by:

\[ A_i = A_i + v \quad \text{for} \quad l \leq i \leq r \]

and the final answer is:

\[ \text{answer} = \sum_{i=0}^{n-1} A_i \]

inputFormat

The first line contains three space-separated integers \(n\), \(m\), and \(k\) where:

  • \(n\) is the number of elements in the array.
  • \(m\) is the number of operations.
  • \(k\) is an extra parameter (not used in this problem).

The second line contains \(n\) space-separated integers representing the array \(A\).

Each of the next \(m\) lines contains three integers \(l\), \(r\), and \(v\) representing an operation to add \(v\) to all elements of the subarray from index \(l\) to index \(r\) (inclusive).

outputFormat

Output a single integer, the sum of the array after all operations have been applied.

## sample
5 2 0
1 2 3 4 5
0 1 2
2 4 -1
16