Time for some video games!
Bob is playing a video game with levels, where the boss on the -th level has a power of . Bob initially has no power. In order to clear a level, Bob needs to have at least as much power as the boss on that level. Also, Bob may only attempt level after clearing all levels with .
Thankfully, Bob can power up! He can spend seconds to gain unit of power permanently by increasing his HP, or he can spend seconds to drink a potion, also netting him unit of power but only for the next boss fight. He may perform either of these actions at any point and as many times as he wants.
Bob wants to clear all the levels. How long does he need?
Subtask 1 [30%]
Subtask 2 [70%]
No additional constraints.
The first line will contain three space-separated integers, , and .
The next line will contain space-separated integers .
Output a single integer, the minimum time Bob needs to spend to beat all the bosses.
3 5 3 1 3 20
It can be proven that it is optimal to first increase Bob's HP by unit, beat the boss on the first level, increase Bob's HP by more units, beat the boss on the second level, and finally drink potions in order to beat the boss on the third level, for a total of seconds.