Sum of negatives

Given a stream of numbers, your task is to calculate the sum up until the first non-negative number. All the numbers after the first non-negative one should be ignored.
It’s guaranteed that the input contains at least a single non-negative number. If the first number is non-negative, the program should print 0.
The program should print the required sum.
Input
Output
-20 -3 -2 -30 0 -1
-55
Explanation: The first non-negative number in the list -20, -3, -2, -30, 0, -1 is 0. So, we should calculate the sum of numbers before 0. This results in -20 -3 -2 -30 = -55.
 

Constraints

Time limit: 2 seconds

Memory limit: 512 MB

Output limit: 1 MB

To check your solution you need to sign in
Sign in to continue