任意门:http://codeforces.com/contest/1114/problem/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*K 个。

暴力扫一遍原序列,如果遇到 这些前 M*K 大的值就取,取到 M 个就分段。

到这里好像没毛病....然而 wa。

有一个细节遗漏了,就是第 M*K 大的值如果不止一个,而是有多个,但这些值按照排序并为在前 M*K 中,但在原序列里,这些值处在比他们大得值前面,那么我们扫描原序列时就会把这些值加进去,而有可能省略了后面更大的值,这个方案肯定不是最优的。

所以第 M*K 个值需要特判!

AC code:

 #include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<vector>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#define INF 0x3f3f3f3f
#define LL long long
using namespace std;
const int MAXN = 2e5+;
int num[MAXN];
int numa[MAXN];
int cnt, anum;
int ans[MAXN], nn;
int N, M, K;
map<int, bool>mmp;
bool cmp(int a, int b)
{
return a > b;
} int main()
{
scanf("%d %d %d", &N, &M, &K);
for(int i = ; i <= N; i++){
scanf("%d", &num[i]);
numa[cnt++] = num[i];
//num[i].no = i;
}
LL ans_sum = 0LL;
sort(numa, numa+cnt, cmp);
for(int i = ; i < M*K; i++){
ans_sum += numa[i];
//mmp[numa[i]] = true;
//printf("%d\n", numa[i]);
}
LL lst = numa[M*K-];
//printf("lst:%d\n", lst);
int j = M*K-;
while(numa[j] == lst && j >= ){
anum++;
j--;
} int tt = ;
for(int i = ; i <= N; i++){
if(num[i] > lst){
tt++;
if(tt == M){
ans[nn++] = i;
tt = ;
}
}
else if(num[i] == lst && anum){
anum--;
tt++;
if(tt == M){
ans[nn++] = i;
tt = ;
}
}
} printf("%I64d\n", ans_sum);
for(int i = ; i < nn-; i++){
printf("%d ", ans[i]);
}
puts("");
return ;
}

CF#538(div2) B. Yet Another Array Partitioning Task 【YY】的更多相关文章

  1. Java虚拟机性能管理神器 - VisualVM(7) 排查JAVA应用程序线程泄漏【转】

    Java虚拟机性能管理神器 - VisualVM(7) 排查JAVA应用程序线程泄漏[转] 标签: javajvm线程泄漏 2015-03-11 19:47 1098人阅读 评论(0) 收藏 举报   ...

  2. Java虚拟机性能管理神器 - VisualVM(6) 排查JAVA应用程序内存泄漏【转】

    Java虚拟机性能管理神器 - VisualVM(6) 排查JAVA应用程序内存泄漏[转] 标签: javajvm内存泄漏监控工具 2015-03-11 18:30 1870人阅读 评论(0) 收藏  ...

  3. Java虚拟机性能管理神器 - VisualVM(9) 排查JAVA应用程序线程死锁【转】

    Java虚拟机性能管理神器 - VisualVM(9) 排查JAVA应用程序线程死锁[转] 标签: javajvm监控工具性能优化 2015-03-11 19:59 1948人阅读 评论(0) 收藏  ...

  4. 机器人操作系统(ROS)教程4:ROS的框架【转】

    转自:http://www.arduino.cn/thread-11351-1-1.html 在进行ROS的代码开发前,有必要了解一些ROS的概念.首先,ROS的系统代码分为两部分:main和univ ...

  5. linux设备驱动归纳总结(十三):1.触摸屏与ADC时钟【转】

    本文转载自:http://blog.chinaunix.net/uid-25014876-id-119723.html linux设备驱动归纳总结(十三):1.触摸屏与ADC时钟 xxxxxxxxxx ...

  6. inux设备驱动归纳总结(五):2.操作硬件——IO内存【转】

    本文转载自:http://blog.chinaunix.net/uid-25014876-id-80627.html inux设备驱动归纳总结(五):2.操作硬件——IO内存 xxxxxxxxxxxx ...

  7. linux设备驱动归纳总结(五):1.在内核空间分配内存【转】

    本文转载自:http://blog.chinaunix.net/uid-25014876-id-79134.html linux设备驱动归纳总结(五):1.在内核空间分配内存 xxxxxxxxxxxx ...

  8. linux设备驱动归纳总结(四):1.进程管理的相关概念【转】

    本文转载自;http://blog.chinaunix.net/uid-25014876-id-64866.html linux设备驱动归纳总结(四):1.进程管理的相关概念 xxxxxxxxxxxx ...

  9. linux设备驱动归纳总结(三):5.阻塞型IO实现【转】

    本文转载自:http://blog.chinaunix.net/uid-25014876-id-60025.html linux设备驱动归纳总结(三):5.阻塞型IO实现 xxxxxxxxxxxxxx ...

随机推荐

  1. android socket 通讯(客户端) 发送数据

    /** ClientSocket通讯类 **/  public class ClientSocket  {     /**服务器地址*/     private String serverUrl=&q ...

  2. 项目开发-->高级功能汇总

    祭奠曾经逝去的青春…… 1.高级功能汇总-->Memcached之ASP.NET实现 2.高级功能汇总-->HubbleDotNet软件安装

  3. php array 数组及数组索引

    array (PHP 4, PHP 5, PHP 7) array — 新建一个数组 说明 array array ([ mixed $... ] ) 创建一个数组.关于数组是什么的信息请阅读数组一节 ...

  4. MyBatis入门篇

    一.什么是MyBatis MyBatis 本是apache的一个开源项目iBatis, 2010年这个项目由apache software foundation 迁移到了google code,并且改 ...

  5. node.js内存缓存的性能情况

    1. WEB 服务性能测试和优化 1.1   测试环境搭建 网络环境:内网 压力测试服务器: 服务器系统:Linux 2.6.18 服务器配置:Intel® Xeon™ CPU 3.40GHz 4 C ...

  6. Docker镜像保存为文件及从文件导入镜像的方法

    参考 1.概述 我们制作好镜像后,有时需要将镜像复制到另一台服务器使用. 能达到以上目的有两种方式,一种是上传镜像到仓库中(本地或公共仓库),但是另一台服务器很肯能只是与当前服务器局域网想通而没有公网 ...

  7. MySQL root 密码修改

    小伙伴要在以前的服务器上装个代码版本控制的软件,要用到数据库,可是想来找去root密码还是忘了,其他已经安装的服务都是用的专用账户配置文件里要找不到root用户的密码.用以下方法将密码强制修改掉: 1 ...

  8. python对excel文件的读写操作

    import xlrd,xlwt data = xlrd.open_workbook('a.xlsx') #读 table = data.sheets()[0] data_list = [] data ...

  9. 移动端Hybird的网络层优化策略

    一.前端代码策略:域名切换(多域名部署),解决DNS缓存及域名劫持 二.客户端策略 客户端在空闲时ping cdn节点域名列表中的域名,测量延时.丢包等数据.如果延迟 > xxx,丢包 > ...

  10. js-TextArea的换行符处理

    js-txt文本处理 写自己主页项目时所产生的小问题拿出来给大家分享分享,以此共勉. ---DanlV TextArea的换行符处理 TextArea文本转换为Html:写入数据库时使用 js获取了t ...