CF BUDDY
← Problems·

1114B · Yet Another Array Partitioning Task

1500 · constructive algorithms, greedy, sortings

Problem: An array bb is called to be a subarray of aa if it forms a continuous subsequence of aa, that is, if it is equal to ala_l, al+1a_{l + 1}, \ldots, ara_r for some l,rl, r.

Suppose mm is some known constant. For any array, having mm or more elements, let's define it's beauty as the sum of mm largest elements of that array. For example:

  • For array x=[4,3,1,5,2]x = [4, 3, 1, 5, 2] and m=3m = 3, the 33 largest elements of xx are 55, 44 and 33, so the beauty of xx is 5+4+3=125 + 4 + 3 = 12.
  • For array x=[10,10,10]x = [10, 10, 10] and m=2m = 2, the beauty of xx is 10+10=2010 + 10 = 20.

You are given an array a1,a2,,ana_1, a_2, \ldots, a_n, the value of the said constant mm and an integer kk. Your need to split the array aa into exactly kk subarrays such that:

  • Each element from aa belongs to exactly one subarray.
  • Each subarray has at least mm elements.
  • The sum of all beauties of kk subarrays is maximum possible.

Input Format: The first line contains three integers nn, mm and kk (2n21052 \le n \le 2 \cdot 10^5, 1m1 \le m, 2k2 \le k, mknm \cdot k \le n) — the number of elements in aa, the constant mm in the definition of beauty and the number of subarrays to split to.

The second line contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n (109ai109-10^9 \le a_i \le 10^9).

Output Format: In the first line, print the maximum possible sum of the beauties of the subarrays in the optimal partition.

In the second line, print k1k-1 integers p1,p2,,pk1p_1, p_2, \ldots, p_{k-1} (1p1<p2<<pk1<n1 \le p_1 < p_2 < \ldots < p_{k-1} < n) representing the partition of the array, in which:

  • All elements with indices from 11 to p1p_1 belong to the first subarray.
  • All elements with indices from p1+1p_1 + 1 to p2p_2 belong to the second subarray.
  • \ldots.
  • All elements with indices from pk1+1p_{k-1} + 1 to nn belong to the last, kk-th subarray.

If there are several optimal partitions, print any of them.

Note: In the first example, one of the optimal partitions is [5,2,5][5, 2, 5], [2,4][2, 4], [1,1,3,2][1, 1, 3, 2].

  • The beauty of the subarray [5,2,5][5, 2, 5] is 5+5=105 + 5 = 10.
  • The beauty of the subarray [2,4][2, 4] is 2+4=62 + 4 = 6.
  • The beauty of the subarray [1,1,3,2][1, 1, 3, 2] is 3+2=53 + 2 = 5.

The sum of their beauties is 10+6+5=2110 + 6 + 5 = 21.

In the second example, one optimal partition is [4][4], [1,3][1, 3], [2,2][2, 2], [3][3].

Sample Cases

Case 1

Input

9 2 3
5 2 5 2 4 1 1 3 2

Output

21
3 5

Case 2

Input

6 1 4
4 1 3 2 2 3

Output

12
1 3 5

Case 3

Input

2 1 2
-1000000000 1000000000

Output

0
1

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback