#K95837. Earliest Negative Cumulative Profit Day
Earliest Negative Cumulative Profit Day
Earliest Negative Cumulative Profit Day
Given a sequence of daily profits for a company, determine the earliest day on which the cumulative profit becomes negative. The days are numbered starting from 1. If the cumulative profit never becomes negative, output -1.
The cumulative profit on day \( i \) is defined as the sum of profits from day 1 to day \( i \). For example, if the profits are [5, -4, -3, 2, 3, -1, -2], the cumulative profits are [5, 1, -2, 0, 3, 2, 0]. In this case, the earliest day when the cumulative profit becomes negative is day 3.
inputFormat
The input is read from standard input (stdin) and consists of two lines:
- The first line contains an integer
n
representing the number of days. - The second line contains
n
space-separated integers which represent the daily profits.
outputFormat
Output a single integer to standard output (stdout) representing the earliest day when the cumulative profit becomes negative. If the cumulative profit never becomes negative, output -1.
## sample7
5 -4 -3 2 3 -1 -2
3
</p>