This page is still under construction.

Parts of this page are still being built. What you see may change.

Street

Time limit2sMemory limit512 MB

Summary
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 nn lots along one side. You want to put up at most kk apartment buildings on them. One building covers an interval of at most tt consecutive lots, and no two buildings may share a lot.

Lot ii carries a height restriction rir_i. A building may not exceed the restriction of any lot it stands on, so a building covering lots ii through jj can be at most H=min⁡{ri,ri+1,…,rj}H = \min\{r_i, r_{i+1}, \dots, r_j\} tall. Its usable facade space is then H×(j−i+1)H \times (j - i + 1).

Pick at most kk 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 k=2k = 2 and t=4t = 4, the best pick is the intervals r3…r5=(12,11,13)r_3 \dots r_5 = (12, 11, 13) and r7…r10=(8,6,6,20)r_7 \dots r_{10} = (8, 6, 6, 20). That is Example 1 in the figure below, and the total usable facade space is 3×min⁡{12,11,13}+4×min⁡{8,6,6,20}=573 \times \min\{12, 11, 13\} + 4 \times \min\{8, 6, 6, 20\} = 57.

On the same street with k=3k = 3 and t=4t = 4, the best pick is the intervals r3…r5=(12,11,13)r_3 \dots r_5 = (12, 11, 13), r7…r9=(8,6,6)r_7 \dots r_9 = (8, 6, 6) and r10=(20)r_{10} = (20). That is Example 2 in the figure, and the total usable facade space is 3×min⁡{12,11,13}+3×min⁡{8,6,6}+1×20=713 \times \min\{12, 11, 13\} + 3 \times \min\{8, 6, 6\} + 1 \times 20 = 71.

Input

The first line holds the number of lots nn, the maximum number of buildings kk, and the maximum number of lots one building may cover tt, separated by spaces (1≤n≤5001 \le n \le 500, 1≤k≤n1 \le k \le n, 1≤t≤n1 \le t \le n). Each of the next nn lines holds one height restriction r1,r2,…,rnr_1, r_2, \dots, r_n, a positive integer at most 100.

Output

Print the largest total usable facade space as a single integer.

Examples2

  1. Example 1

    Input
    10 2 4
    7
    3
    12
    11
    13
    4
    8
    6
    6
    20
    
    Expected output
    57
    
  2. Example 2

    Input
    10 3 4
    7
    3
    12
    11
    13
    4
    8
    6
    6
    20
    
    Expected output
    71