#P1089. [NOIP 2004 提高组] 津津的储蓄计划
[NOIP 2004 提高组] 津津的储蓄计划
Description
Jinjin manages her pocket money by herself. At the beginning of each month, mom gives Jinjin yuan. Jinjin makes a budget for that month’s expenses, and she always keeps the actual expenses equal to the budget.
To teach Jinjin how to save, mom proposes that Jinjin may deposit any whole hundreds with her at any time, and at year end she will add and return it to Jinjin. Therefore, Jinjin makes a savings plan: at the beginning of each month, after receiving the pocket money from mom, if she expects that by the end of this month she will have at least yuan left on hand, she will deposit all the full hundreds with mom, keeping the remainder herself.
For example, at the beginning of month , Jinjin still has yuan on hand, and mom gives yuan. Jinjin plans to spend yuan in month , so she deposits yuan with mom and keeps yuan. By the end of month , Jinjin will have yuan left.
Jinjin finds that the main risk of this savings plan is that the money deposited with mom cannot be withdrawn before year end. It may happen that at the beginning of some month, the money Jinjin has on hand plus this month’s money from mom is not enough for that month’s original budget. If this happens, Jinjin will have to scrimp that month and cut the budget.
Now, given Jinjin’s monthly budgets from January to December of year , determine whether such a situation occurs. If not, compute how much money Jinjin will have on hand at the end of year , after mom returns the deposited money plus to Jinjin.
Input Format
lines of data, each containing a non-negative integer less than , representing the budgets for months through .
Output Format
A single integer. If, during the implementation of the savings plan, there is a month when the money is not enough, output , where is the first such month; otherwise, output how much money Jinjin will have on hand at the end of year .
Note that on Luogu you should use standard input and output, not file I/O.
290
230
280
200
300
170
340
50
90
80
200
60
-7
290
230
280
200
300
170
330
50
90
80
200
60
1580
Hint
Translated by ChatGPT 5
京公网安备 11011102002149号