luogu#P12076. [OOI 2025] Cute Subsequences

[OOI 2025] Cute Subsequences

题目描述

You are given an array of nn positive integers a1a_1, a2a_2, \ldots, ana_n, as well as a positive integer kk. You need to divide the array into kk non-empty subsequences such that each element of the array belongs to exactly one subsequence. A subsequence is a sequence that can be obtained from another sequence by deleting some elements without changing the order of the remaining elements.

Let the ii-th subsequence contain elements with indices j1<<jlj_1 < \ldots < j_l. The value\textit{value} of this subsequence is defined as the maximum value of ajm+ma_{j_m} + m for all mm from 11 to ll.

The cost\textit{cost} of dividing the array into kk subsequences is the sum of the values\textit{values} of these subsequences.

Find the maximum cost\textit{cost} of the division.

输入格式

The first line contains two positive integers nn and kk (1kn5000001 \leq k \leq n \leq 500\,000) --- the size of the array and the number of subsequences to divide it into.

The second line contains nn positive integers a1a_1, a2a_2, \ldots, ana_n (1ai1091 \leq a_i \leq 10^9) --- the elements of the array.

输出格式

Output the maximum cost\textit{cost} of dividing the given array into kk non-empty subsequences.

5 3
3 7 10 1 2
24

提示

Note

In the sample test, the array can be divided into [3,10][3, 10], [7][7], [1,2][1, 2]. Then the answer will be (10+2)+(7+1)+(2+2)=12+8+4=24(10 + 2) + (7 + 1) + (2 + 2) = 12 + 8 + 4 = 24.

Scoring

The tests for this problem consist of six groups. Points for each group are given only if all tests of the group and all tests of the required groups are passed.

Group Points Additional Constraints: nn Additional Constraints: kk Required Groups Comment
0 -- -- -- Examples.
1 14 n8n \le 8 0
2 19 -- k=2k = 2 --
3 17 -- ai+1aia_{i+1} \leq a_i
4 21 ai+1ai1a_{i+1} \geq a_i - 1
5 15 n1000n \leq 1000 0, 1
6 14 -- 0 -- 5