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
GNU G++17
0 ms
0 KB
Compilation Error