Positive partial sums

The partial sums of a list of integers vv are:

v[0]
v[0]+v[1]
v[0]+v[1]+v[2]
...
v[0]+v[1]+v[2]+...+v[len(v)-1]

Design a function @sumes_parcials_pos(v)@ that, given a list of integers vv, returns the list containing the positive partial sums of the list vv, that is, those that are greater than zero.

For example, if vv is [0, 3, -4, -5, 7], then the partial sums are

0
0+3 == 3
0+3+(-4) == -1
0+3+(-4)+(-5) == -6
0+3+(-4)+(-5)+7 == 1

and, therefore, the list with the two positive partial sums must be returned

[3, 1] == [0+3, 0+3+(-4)+(-5)+7]

DON’T use the Python function sum(v[i:j]).

Sample session

Problem information

Author: InfBesos

Generation: 2026-01-25T16:54:26.417Z

© Jutge.org, 2006–2026.
https://jutge.org