Street
Time limit2sMemory limit512 MB
Choose up to k non-overlapping blocks of at most t lots to maximize total block length times its minimum height limit.
- Level
Medium6 of 10
- Topics
- Dynamic programming, Intervals
- Solved
- No attempts yet
Problem
A street has lots along one side. You want to put up at most apartment buildings on them. One building covers an interval of at most consecutive lots, and no two buildings may share a lot.
Lot carries a height restriction . A building may not exceed the restriction of any lot it stands on, so a building covering lots through can be at most tall. Its usable facade space is then .
Pick at most non-overlapping intervals so that the total usable facade space is as large as possible.
Consider a street of length 10 whose lots carry the restrictions 7, 3, 12, 11, 13, 4, 8, 6, 6, 20.
With and , the best pick is the intervals and . That is Example 1 in the figure below, and the total usable facade space is .

On the same street with and , the best pick is the intervals , and . That is Example 2 in the figure, and the total usable facade space is .
Input
The first line holds the number of lots , the maximum number of buildings , and the maximum number of lots one building may cover , separated by spaces (, , ). Each of the next lines holds one height restriction , a positive integer at most 100.
Output
Print the largest total usable facade space as a single integer.