CF1175G.Yet Another Partiton Problem

NOI/NOI+/CTSC

通过率:0%

时间限制:5.00s

内存限制:512MB

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 (r−l+1)⋅max⁡l≤i≤r(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.

给你一个数组 a1,a2,…,ana_1, a_2, \dots, a_n。你需要将其划分为 kk 个子段(即每个元素恰好属于其中一个子段)。

子段 al,al+1,…,ara_l, a_{l+1}, \dots, a_r 的权重定义为 (r−l+1)⋅max⁡l≤i≤r(ai)(r - l + 1) \cdot \max\limits_{l \le i \le r}(a_i)。一个划分的权重定义为该划分中所有子段的权重之和。

请找出权重最小的划分。

输入格式

The first line contains two integers nn and kk (1≤n≤2⋅1041 \le n \le 2 \cdot 10^4, 1≤k≤min⁡(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 (1≤ai≤2⋅1041 \le a_i \le 2 \cdot 10^4) — the array aa.

第一行包含两个整数 nn 和 kk(1≤n≤2⋅1041 \le n \le 2 \cdot 10^4,1≤k≤min⁡(100,n)1 \le k \le \min(100, n))—— 分别表示数组 aa 的长度以及划分中子区间的个数。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(1≤ai≤2⋅1041 \le a_i \le 2 \cdot 10^4)—— 数组 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.

第一个样例的最优划分如下:66 11 77 ∣\bigg| 44。

第二个样例的最优划分如下:66 ∣\bigg| 11 ∣\bigg| 77 44。

第三个样例的一个最优划分如下:55 ∣\bigg| 11 55 ∣\bigg| 11 ∣\bigg| 55。

输入解题思路,AI测评打分。不知道怎么写?

首页