#P1089. Savings Plan
Savings Plan
Savings Plan
Jinjin manages her own allowance. Every month at the beginning, her mother gives her \(300\) yuan. Jinjin plans her spending for the month and always manages to exactly spend her budgeted amount. To encourage her to save, her mother offers that Jinjin may deposit any amount that is an exact multiple of \(100\) yuan into her account at any time. At the end of the year, her mother returns the deposited money with an additional \(20\%\) bonus.
Jinjin's saving strategy is as follows: at the beginning of each month, after receiving the \(300\) yuan, she checks her total money in hand (i.e. the leftover from the previous month plus \(300\)). Let this total be \(T\) and let the month’s planned spending be \(b\). If she predicts that after spending \(b\) yuan she will have at least \(100\) yuan left (that is, if \(T - b \ge 100\)), then she deposits the maximum amount that is a multiple of \(100\) while still ensuring that she has enough to cover her budget. Formally, she deposits \(D = 100 \times \lfloor (T - b) / 100 \rfloor\) provided that \(T - b \geq 100\); otherwise, she deposits nothing. After depositing \(D\), she uses the remaining \(T - D\) yuan to cover her spending \(b\). If at any month she finds that \(T - D < b\) (i.e. she does not have enough money to meet her budget), it means she must cut back on her spending.
Your task is: given the planned monthly spending for each month from January to December of 2004, determine whether there will be a month when Jinjin cannot cover her planned spending. If such a situation occurs, output \(-1\). Otherwise, compute the total money Jinjin will have at the end of 2004. This total money consists of the money she has left in hand after December and the amount that her mother returns at the end of the year; note that the deposited money is returned with an additional \(20\%\) bonus.
Hint: Simulate each month. Let the leftover money at the beginning of the month be \(L\) (with \(L = 0\) initially). Then, after receiving \(300\) yuan, the total becomes \(T = L + 300\). If \(T - b \ge 100\), deposit \(D = 100 \times \lfloor (T - b)/100 \rfloor\) (choose the maximum multiple of 100 such that \(T - D \ge b\)). Then update the leftover money as \(L = T - D - b\). The cumulative deposited amount is accumulated across months, and at year end, the final money is \(L + 1.2 \times (\text{total deposits})\).
inputFormat
The input consists of a single line containing 12 space-separated integers \(b_1, b_2, \dots, b_{12}\), where \(b_i\) represents the planned spending for the \(i\)-th month (from January to December 2004).
outputFormat
If in any month Jinjin does not have enough money to cover her planned spending, output \(-1\). Otherwise, output a single integer representing the total money Jinjin will have at the end of 2004 (the money left in hand plus the deposited amount returned with a 20% bonus).
sample
180 180 180 180 180 180 180 180 180 180 180 180
1720