z-paradajz
Mr. Little Z wants to live a healthy life, so he decided to eat exactly one tomato every day.
The price of tomatoes changes every day, so Mr. Little Z went to a fortune teller to get predictions for the prices of tomatoes for the next n days. Mr. Little will buy tomatoes the most optimal way, because he wants to save some money. However, he must make sure that the tomatoes do not go bad. To be more accurate, if you buy a tomato on the i-th day it will be healthy until the (i+d-1)th day. So, the lifespan of a tomato is d. *Important: Mr. Little Z can buy as many tomatoes as he wants in one day!
For the given tomatoes' prices in the next n days and the lifespan of tomatoes d, calculate the minimum amount of money that Mr. Little Z has to spend in order to eat one tomato for each of the next n days.
8 3
1
2
3
2
4
1
3
2Output:
10Explanation: Mr. Little Z will buy 3 tomatoes on the 1st day, then he'll buy 2 tomatoes on the 4th day, and finally he will buy 3 tomatoes on the 6th day.
Comment: Mr. Little Z can eat a tomato on the same day he bought it.
Submit solution
Coming laterThe grading service will be connected in a later migration step. You can inspect the task and your previous results now.