
ZOJ Problem Set  3632
Watermelon is very popular in the hot summer. Students in ZJUICPC Team also love watermelon very much and they hope that they can have watermelon to eat every day during the summer vacation. Suppose there are n days and every day they can buy only one watermelon. The price of watermelon may be different in each day. Besides, sometimes the watermelon they choose to buy may be very big, which means if they buy this watermelon, they will need several days to eat it up. The students want to spend the minimum money to buy enough watermelon so that they can eat watermelon every day. Can you help them? Notice: When they buy a new watermelon, if they still have an old watermelon, they will throw the old one into dustbin. For example, suppose they buy a watermelon on the fisrt day, and it needs 4 days to eat up the watermelon. But if they buy a new watermelon on the second day and it needs 2 days to eat up the new watermelon, then they will throw the old one, and they have to buy a new watermelon on the fourth day since they don't have any watermelon to eat on that day. Input
The input contains multiple test cases ( no more than 200 test cases ). OutputFor each case, output one line with an integer which is the minimum money they must spend so that they can have watermelon to eat every day. Sample Input4 10 20 1 40 3 2 3 1 Sample Output11 Author: HUANG, Qiao Contest: ZOJ Monthly, July 2012 