#C6353. Perform Operations on Integer List

    ID: 50104 Type: Default 1000ms 256MiB

Perform Operations on Integer List

Perform Operations on Integer List

You are given an array of n integers and a list of q operations. In each operation, a single integer x is provided, and you add x to every element of the array. The operations are cumulative, meaning that each update affects subsequent operations.

Your task is to compute and output the sum of the elements in the array after each operation. Formally, if the initial array is \(a_1, a_2, \dots, a_n\) and the sum is \(S = \sum_{i=1}^n a_i\), after an operation with value \(x\), the new sum becomes \(S + x \cdot n\). You need to process all operations sequentially and output the updated sum after each operation.

inputFormat

The input is given via standard input (stdin) and has the following format:

  • The first line contains two integers \(n\) and \(q\), where \(n\) is the number of elements in the array and \(q\) is the number of operations.
  • The second line contains \(n\) integers representing the array elements.
  • The third line contains \(q\) integers representing the operations. Each integer denotes the value \(x\) to be added to every element of the array.

outputFormat

For each of the \(q\) operations, output the sum of the array after applying that operation. Each result should be printed on a new line to the standard output (stdout).

## sample
5 2
1 2 3 4 5
2 3
25

40

</p>