PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#PS0000116. Dãy tổng tích lũy (Running Sum of 1d Array)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Dãy tổng tích lũy (Running Sum of 1d Array)
Running Sum of 1d Array
Source: LeetCode
Version: Phuoc Hung OJ Extended
Problem Statement
An array of integers is indexed from 0. At index , the running sum includes every element from the beginning of the array through . Find the entire array in order.
Input
The first line contains integer .
The second line contains integers .
Output
Print space-separated integers on one line.
Subtasks
- Subtask 1 (20 points): ; ; .
- Subtask 2 (30 points): ; ; ; ().
- Subtask 3 (50 points): ; ; .
Example 1
Input
4
1 2 3 4
Output
1 3 6 10
Explanation
The successive sums are , , , and .
Example 2
Input
5
1 1 1 1 1
Output
1 2 3 4 5
Explanation
Every value equals 1, so the sum of the first elements is . The five results are 1, 2, 3, 4, 5.
Example 3
Input
5
3 1 2 10 1
Output
3 4 6 16 17
Explanation
Start with 3; adding 1, 2, 10, and 1 successively yields 4, 6, 16, and 17.