#C14378. Cumulative Sum with Reset

    ID: 44020 Type: Default 1000ms 256MiB

Cumulative Sum with Reset

Cumulative Sum with Reset

Given a list of integers, compute a cumulative sum of the list with a twist: whenever a negative number is encountered, the cumulative sum resets to that negative number, and subsequent positive numbers start a new sum. Formally, for a sequence ( a_1, a_2, \ldots, a_n ), define the output sequence ( s_1, s_2, \ldots, s_n ) by

[ s_i = \begin{cases} a_i, & \text{if } a_i < 0, \ s_{i-1} + a_i, & \text{if } a_i \ge 0, \end{cases} ]

with a reset occurring immediately after processing a negative number. If the list is empty, output an empty sequence.

inputFormat

The first line of input contains a single integer ( n ) (( 0 \le n \le 10^5 )), which indicates the number of elements. The second line contains ( n ) space-separated integers.

outputFormat

Output the cumulative sum sequence as a single line of space-separated integers. If there are no elements, output an empty line.## sample

4
1 2 3 4
1 3 6 10

</p>