Codeforces Round #538 (Div. 2).b(思维)

B. Yet Another Array Partitioning Task

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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:

  • 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,…,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:

  • 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

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<p2<…<pk−1<n1≤p1<p2<…<pk−1<n) representing the partition of the array, in which:

  • All elements with indices from 11 to p1p1 belong to the first subarray.
  • All elements with indices from p1+1p1+1 to p2p2 belong to the second subarray.
  • …….
  • All elements with indices from pk−1+1pk−1+1 to nn belong to the last, kk-th subarray.

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

Examples

input

Copy

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

output

Copy

21
3 5 

input

Copy

6 1 4
4 1 3 2 2 3

output

Copy

12
1 3 5 

input

Copy

2 1 2
-1000000000 1000000000

output

Copy

0
1 

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].

解析:

这个题目是给你n个数据,让你分成k段,每一段至少m个数,并且把每一段的前m大的数求和
输出求和的结果,和分段的位置

我们把排序后的前m*k个位置标记,然后遍历,只算被标记的,没m个输出一次

ac:

#include<bits/stdc++.h>
#define ll long long
#define MAXN 200005
using namespace std;

struct node
{
    int a,b;
}x[MAXN];

bool cmp(node x,node y)
{
    return x.a>y.a;
}

ll sum=0;
int vis[MAXN]={0};

int main()
{
    int n,m,k;
    ll sum=0;
    scanf("%d%d%d",&n,&m,&k);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&x[i].a);
        x[i].b=i+1;
    }
    sort(x,x+n,cmp);
    for(int i=0;i<k*m;i++)
    {
        vis[x[i].b]=1;
        sum+=x[i].a;
    }
    printf("%lld\n",sum);
    int j=0,g=0;
    for(int i=0;i<n&&g<k-1;i++)
    {
        if(vis[i]==1) j++;
        if(j==m)
        {
            if(g>0)
                printf(" ");
            printf("%d",i);
            g++;
            j=0;
        }
    }
    printf("\n");
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值