CF1175G.Yet Another Partiton Problem

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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.

输入输出样例

  • 输入#1

    4 2
    6 1 7 4
    

    输出#1

    25
    
  • 输入#2

    4 3
    6 1 7 4
    

    输出#2

    21
    
  • 输入#3

    5 4
    5 1 5 1 5
    

    输出#3

    21
    

说明/提示

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 .

首页