Task DescriptionDiscussion (0)

The first line of the standard input contains two numbers,

To the standard output write one number corresponding to the minimum amount of money Mr. Little Z has to spend in order to eat one tomato every day.

Task :: 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.**INPUT:**

The first line of the standard input contains two numbers,

**n**and

**d**. 1 <=

**n**,

**d**<= 200000, where

**d**<=

**n**. Each of the next

**n**lines contains prices for tomatoes

**c**(

_{i}**i**= 1..

**n**), where the maximum price for each tomato is 1000.

**OUTPUT:**

To the standard output write one number corresponding to the minimum amount of money Mr. Little Z has to spend in order to eat one tomato every day.

Input:

Output:

Explanation: 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.

**8 3**

1

2

3

2

4

1

3

2

1

2

3

2

4

1

3

2

Output:

**10**

Explanation: 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

Available Languages

Task info

Name: | z-paradajz |

Time: | 0.25 sec. |

Memory: | 16 MB |

#Tests: | 20 |

Author: | Eric D.Demaine i Charles E. Leiserson |

AddedBy: | admin |

Task Ratings

Difficulty: | 3.7 (36 votes) |

Quality: | 4.2 (35 votes) |

Acceptance Rate

Recent Submissions

Fastest Solutions

User | Time |
---|---|

johndoe | 0.061 s. |

nikola_12345 | 0.061 s. |

Al3kSaNdaR | 0.063 s. |

tgudlek | 0.068 s. |

smiljo | 0.071 s. |

hadzem | 0.09 s. |

ja_bre | 0.096 s. |

matteo123 | 0.122 s. |

kole95 | 0.136 s. |

sokokaleb | 0.148 s. |

Solved By