#G. Yet Another Partiton Problem

    Type: RemoteJudge 5000ms 512MiB

Yet Another Partiton Problem

You cannot submit for this problem because the contest is ended. You can click "Open in Problem Set" to view this problem in normal mode.

Description

You are given array a1,a2,,ana_1, a_2, \dots, a_n. You need to split it into kk subsegments (so every element is included in exactly one subsegment).

The weight of a subsegment al,al+1,,ara_l, a_{l+1}, \dots, a_r is equal to (rl+1)maxlir(ai)(r - l + 1) \cdot \max\limits_{l \le i \le r}(a_i). The weight of a partition is a total weight of all its segments.

Find the partition of minimal weight.

The first line contains two integers nn and kk (1n21041 \le n \le 2 \cdot 10^4, 1kmin(100,n)1 \le k \le \min(100, n)) — the length of the array aa and the number of subsegments in the partition.

The second line contains nn integers a1,a2,,ana_1, a_2, \dots, a_n (1ai21041 \le a_i \le 2 \cdot 10^4) — the array aa.

Print single integer — the minimal weight among all possible partitions.

Input

The first line contains two integers nn and kk (1n21041 \le n \le 2 \cdot 10^4, 1kmin(100,n)1 \le k \le \min(100, n)) — the length of the array aa and the number of subsegments in the partition.

The second line contains nn integers a1,a2,,ana_1, a_2, \dots, a_n (1ai21041 \le a_i \le 2 \cdot 10^4) — the array aa.

Output

Print single integer — the minimal weight among all possible partitions.

Sample Input 1

4 2
6 1 7 4

Sample Output 1

25

Sample Input 2

4 3
6 1 7 4

Sample Output 2

21

Sample Input 3

5 4
5 1 5 1 5

Sample Output 3

21

Note

The optimal partition in the first example is next: 66 11 77 \bigg| 44.

The optimal partition in the second example is next: 66 \bigg| 11 \bigg| 77 44.

One of the optimal partitions in the third example is next: 55 \bigg| 11 55 \bigg| 11 \bigg| 55.

20240326集训

Not Attended
Status
Done
Rule
IOI
Problem
7
Start at
2024-3-26 19:00
End at
2024-3-26 21:00
Duration
2 hour(s)
Host
Partic.
14