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 alal, al+1al+1, ……, arar 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:
You are given an array a1,a2,…,ana1,a2,…,an, the value of the said constant mm and an integer kk. Your need to split the array aa into exactly kksubarrays such that:
Input
The first line contains three integers nn, mm and kk (2≤n≤2⋅1052≤n≤2⋅105, 1≤m1≤m, 2≤k2≤k, m⋅k≤nm⋅k≤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,…,ana1,a2,…,an (−109≤ai≤109−109≤ai≤109).
Output
In the first line, print the maximum possible sum of the beauties of the subarrays in the optimal partition.
In the second line, print k−1k−1 integers p1,p2,…,pk−1p1,p2,…,pk−1 (1≤p1 If there are several optimal partitions, print any of them. Examples input Copy output Copy input Copy output Copy input Copy output Copy 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 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]. 题解:题目给出n,m,k和一个长度为n的数组,并定义一个数组前m大的数为其的优美度,问如何将这个n个元素的数组分成k个子数组,使得这k个小数组的优美度之和最大,并且每一个小数组至少有m个值(sure)。本题的标签有贪心和排序,既然是贪心就一如既往的将该数组中前m*k大的数之和放到ans里面,位置的要求可以再另开一个c数组,记录每一个值的下标,在运用C++中优先队列的时候内容为pair类型,first为值,second为下标,在记录的过程中下标的大小顺序可能会弄乱,再sort一波,依次输出c数组中的内容即可。
9 2 3
5 2 5 2 4 1 1 3 2
21
3 5
6 1 4
4 1 3 2 2 3
12
1 3 5
2 1 2
-1000000000 1000000000
0
1
#include