#C9999. Predict Out-Of-Stock Day
Predict Out-Of-Stock Day
Predict Out-Of-Stock Day
You are given a product's daily sales data and its current stock. Your task is to predict the day on which the product will run out of stock. Specifically, for each day you subtract the daily sales from the current stock, and if at any day the remaining stock becomes negative, that day is the out-of-stock day. Otherwise, if the product never runs out, output -1.
Formally, if the initial stock is \( s \) and the sales for day \( i \) are given by \( d_i \), find the smallest integer \( k \) such that
[ s - \sum_{i=1}^{k} d_i < 0 ]
Return the 1-indexed day \( k \). If such a day does not exist, output -1.
inputFormat
The input is read from standard input (stdin) in the following format:
- The first line contains a single integer \( n \), the number of days.
- The second line contains \( n \) space-separated integers representing the daily sales \( d_1, d_2, \dots, d_n \).
- The third line contains a single integer representing the current stock \( s \).
outputFormat
The output is a single integer written to standard output (stdout): the 1-indexed day on which the product runs out of stock, or -1 if it never does.
## sample5
2 3 1 5 6
10
4