Source Code
n = int(input())
a = list(map(int, input().strip().split()))

ans = []
for i in a:
    if i > 0:
        ans.append(i)
    elif i < 0:
        while i <= 0 and ans:
            i += ans[-1]
            ans.pop()
        ans.append(i)

print(" ".join(map(str, ans)))
Copy
b m-salti
Python 3
166 ms
39.5 MB
Wrong Answer