CodeChef PESU ECC Chapter
00:00Log in

Running Sum of Array

Easy1s limit256 MB

Given an array nums of n integers, compute the running sum (prefix sum) of the array.

The running sum at index i is defined as the sum of all elements from index 0 up to index i (inclusive): runningSum[i] = nums[0] + nums[1] + ... + nums[i].

Print the resulting running sum array.

Input Format

The first line contains a single integer n — the number of elements in the array.

The second line contains n space-separated integers nums_1, nums_2, ..., nums_n.

Output Format

Print n space-separated integers representing the running sum of the array. If n = 0, leave the output empty.

Constraints

  • 0 <= n <= 10^5
  • -10^9 <= nums_i <= 10^9

Sample 1

Input
4
1 2 3 4
Output
1 3 6 10

Explanation

Running sum is obtained as follows: [1, 1+2, 1+2+3, 1+2+3+4] = [1, 3, 6, 10].

Sample 2

Input
5
1 1 1 1 1
Output
1 2 3 4 5

Explanation

Running sum is [1, 1+1, 1+1+1, 1+1+1+1, 1+1+1+1+1] = [1, 2, 3, 4, 5].

Code
Loading editor…
Auto-savedC++
Case 1using sample

Run uses this input. Submit always judges the hidden tests.