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

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大的数,其实可以转化成,求这一组数前m*k大的数之和。
至于求分段的位置,这个就有点麻烦了,可以把每一个位置初始标记为0,
然后在求sum的同时,将求过的数位置标记成1,之后求分段位置的时候,
就可以进行累加,一旦累加之和为m,说明这m个数组成了一段,也就是在这个位置将数组分段。

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
using namespace std;
typedef long long ll;
const int maxn=2e5+10;
struct node
{
int x,id;
}a[maxn];
bool vis[maxn];
bool cmp(node a,node b)
{
return a.x>b.x;
}
int main()
{
int n,m,k;
memset(vis,0,sizeof(vis));
scanf("%d%d%d",&n,&m,&k);
for(int i=1;i<=n;i++)
{
scanf("%d",&a[i].x);
a[i].id=i;
}
sort(a+1,a+1+n,cmp);
ll sum=0;
for(int i=1;i<=m*k;i++)
{
sum+=a[i].x;
vis[a[i].id]=1;
//printf("a.id=%d\n",a[i])
}
printf("%I64d\n",sum);
int s=0;;
for(int i=1;i<=n;i++)
{
s=s+vis[i];
// printf("%d %d\n",i,s);
if(s==m&&k!=1)
{
k--;
s=0;
printf("%d ",i);
}
}
printf("\n");
return 0;
}

  

B. Yet Another Array Partitioning Task ——cf的更多相关文章

  1. CF#538(div2) B. Yet Another Array Partitioning Task 【YY】

    任意门:http://codeforces.com/contest/1114/problem/B B. Yet Another Array Partitioning Task time limit p ...

  2. CF1114B Yet Another Array Partitioning Task

    CF1114B Yet Another Array Partitioning Task 贪心,选择前 \(k*m\) 大的元素对答案进行贡献. 每次划分时,从当前位置往后扫,扫到 \(m\) 个前 \ ...

  3. CF1114B Yet Another Array Partitioning Task(贪心,构造题)

    我至今不敢相信我被这么一道简单的题卡了这么久……看来还是太弱了…… 题目链接:CF原网 题目大意:定义一个序列的“美丽度”为这个序列前 $m$ 大的数的和.现在有一个长度为 $n$ 的序列,你需要把它 ...

  4. 【Codeforces 1114B】Yet Another Array Partitioning Task

    [链接] 我是链接,点我呀:) [题意] 让你把数组分成k个连续的部分 使得每个部分最大的m个数字的和最大 [题解] 把原数组降序排序 然后选取前m*k个数字打标记 然后对于原数组 一直贪心地取 直到 ...

  5. Codeforces - 1114B - Yet Another Array Partitioning Task - 构造 - 排序

    https://codeforces.com/contest/1114/problem/B 一开始叫我做,我是不会做的,我没发现这个性质. 其实应该很好想才对,至少要选m个元素,其中m个作为最大值,从 ...

  6. codeforces-473D Mahmoud and Ehab and another array construction task (素数筛法+贪心)

    题目传送门 题目大意:先提供一个数组,让你造一个数组,这个数组的要求是 1 各元素之间都互质  2  字典序大于等于原数组  3 每一个元素都大于2 思路: 1.两个数互质的意思就是没有公因子.所以每 ...

  7. Codeforces 959D. Mahmoud and Ehab and another array construction task(构造, 简单数论)

    Codeforces 959D. Mahmoud and Ehab and another array construction task 题意 构造一个任意两个数都互质的序列,使其字典序大等于a序列 ...

  8. D. Mahmoud and Ehab and another array construction task 因子分界模板+贪心+数学

    D. Mahmoud and Ehab and another array construction task 因子分解模板 题意 给出一个原序列a 找出一个字典序大于a的序列b,使得任意 \(i!= ...

  9. CF959D Mahmoud and Ehab and another array construction task 数学

    Mahmoud has an array a consisting of n integers. He asked Ehab to find another array b of the same l ...

随机推荐

  1. 将Python脚本打包成可执行文件

    Python是一个脚本语言,被解释器解释执行.它的发布方式: .py文件:对于开源项目或者源码没那么重要的,直接提供源码,需要使用者自行安装Python并且安装依赖的各种库.(Python官方的各种安 ...

  2. Xhprof graphviz Warning: proc_open() [function.proc-open]: CreateProcess failed, error code 解决方法

    Xhprof在windows下点击[View Full Callgraph]调用graphviz软件时.警告Warning: proc_open() [function.proc-open]: Cre ...

  3. mybatis_05动态SQL_if和where

    If标签:作为判断入参来使用的,如果符合条件,则把if标签体内的SQL拼接上. 注意:用if进行判断是否为空时,不仅要判断null,也要判断空字符串‘’: Where标签:会去掉条件中的第一个and符 ...

  4. 【Java每日一题】20170209

    20170208问题解析请点击今日问题下方的“[Java每日一题]20170209”查看(问题解析在公众号首发,公众号ID:weknow619) package Feb2017; public cla ...

  5. Java高并发 -- 线程池

    Java高并发 -- 线程池 主要是学习慕课网实战视频<Java并发编程入门与高并发面试>的笔记 在使用线程池后,创建线程变成了从线程池里获得空闲线程,关闭线程变成了将线程归坏给线程池. ...

  6. 用GitHub Issue取代多说,是不是很厉害?

    摘要: 别了,多说,拥抱Gitment. 2017年6月1日,多说正式下线,这多少让人感觉有些遗憾.在比较了多个博客评论系统,我最终选择了Gitment作为本站的博客评论系统: UI简洁,适合我的博客 ...

  7. 四、HTTP控制器

    1.控制器的作用:数据和视图之间的桥梁 2.控制器创建方法: (1)手动创建 <?php namespace App\Http\Controllers; class UserController ...

  8. VMWAR-workstatuon

    https://blog.csdn.net/felix__h/article/details/82853501 链接中的秘钥可用~感谢原文作者 下载安装: 官网下载地址:https://www.vmw ...

  9. vue+vuecli+webpack中使用mockjs模拟后端数据

    前言 使用mockjs可以事先模拟数据,前提是和后端约定好了数据接口,怎样的数据.使用mock就可以生成你要的数据了,从而实现开发时前后端分离. 其主要功能是: 基于数据模板生成模拟数据. 基于HTM ...

  10. win7下利用ftp实现华为路由器的配置文件上传和下载

    win7下利用ftp实现华为路由器的配置文件上传和下载 1.  Win7下ftp的安装和配置 (1)开始—>控制面板—>程序—>程序和功能—>打开或关闭Windows功能 (2 ...