Watching Mooloo
InterviewTime limit1sMemory limit1024 MB
Given N watch days, find the minimum total cost of subscriptions where a subscription of length d costs d plus K and must cover every watch day.
- Level
Medium5 of 10
- Topics
- Dynamic programming, Intervals, Greedy
- Solved
- No attempts yet
Problem
Bessie likes to watch shows on Mooloo. Because Bessie is a busy cow, she has planned a schedule for the next () days that she will watch Mooloo. Because Mooloo is a paid subscription service, she needs to decide how to minimize the amount of money she pays.
Mooloo has an interesting subscription system: it costs () moonies to subscribe to Mooloo for consecutive days. You can start a subscription at any time, and you can start a new subscription as many times as you want once your current subscription expires. Figure out the minimum amount of moonies Bessie needs to pay to fulfill her schedule.
Input
The first line contains integers and .
The second line contains integers describing the days Bessie will watch Mooloo: .
Output
Note that the large size of integers involved in this problem may require the use of 64-bit integer data types (e.g., a "long long" in C/C++).