Codeforces - 1114B - Yet Another Array Partitioning Task - 构造 - 排序
https://codeforces.com/contest/1114/problem/B
一开始叫我做,我是不会做的,我没发现这个性质。
其实应该很好想才对,至少要选m个元素,其中m个作为最大值,从总体上考虑的话,要是能区分哪些元素处于前m*k大,就把他们m个一组直接划分就好了。
魔理沙dalao说还不需要用sort来降序,用nth_element,我还在想怎么从序列中复原出标号,其实只需要在一起nth_element就好了。
#include<bits/stdc++.h>
using namespace std;
#define ll long long int n,m,k;
pair<int,int> a[];
int idx[]; int main(){
scanf("%d%d%d",&n,&m,&k);
for(int i=;i<n;i++){
scanf("%d",&a[i].first);
a[i].second=i;
}
nth_element(a,a+m*k,a+n,greater<pair<int,int> >()); ll sum=;
for(int i=;i<m*k;i++){
sum+=a[i].first;
idx[i]=a[i].second;
}
printf("%lld\n",sum);
sort(idx,idx+m*k);
for(int i=;i<m*k;i++){
if(i%m==&&i){
if(i!=m)
printf(" ");
printf("%d",idx[i]);
}
}
printf("\n");
}
Codeforces - 1114B - Yet Another Array Partitioning Task - 构造 - 排序的更多相关文章
- 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 ...
- B. Yet Another Array Partitioning Task ——cf
B. Yet Another Array Partitioning Task time limit per test 2 seconds memory limit per test 256 megab ...
- CF1114B Yet Another Array Partitioning Task
CF1114B Yet Another Array Partitioning Task 贪心,选择前 \(k*m\) 大的元素对答案进行贡献. 每次划分时,从当前位置往后扫,扫到 \(m\) 个前 \ ...
- Codeforces 959D. Mahmoud and Ehab and another array construction task(构造, 简单数论)
Codeforces 959D. Mahmoud and Ehab and another array construction task 题意 构造一个任意两个数都互质的序列,使其字典序大等于a序列 ...
- 【Codeforces 1114B】Yet Another Array Partitioning Task
[链接] 我是链接,点我呀:) [题意] 让你把数组分成k个连续的部分 使得每个部分最大的m个数字的和最大 [题解] 把原数组降序排序 然后选取前m*k个数字打标记 然后对于原数组 一直贪心地取 直到 ...
- CF1114B Yet Another Array Partitioning Task(贪心,构造题)
我至今不敢相信我被这么一道简单的题卡了这么久……看来还是太弱了…… 题目链接:CF原网 题目大意:定义一个序列的“美丽度”为这个序列前 $m$ 大的数的和.现在有一个长度为 $n$ 的序列,你需要把它 ...
- D. Mahmoud and Ehab and another array construction task 因子分界模板+贪心+数学
D. Mahmoud and Ehab and another array construction task 因子分解模板 题意 给出一个原序列a 找出一个字典序大于a的序列b,使得任意 \(i!= ...
- Codeforces 442C Artem and Array(stack+贪婪)
题目连接:Codeforces 442C Artem and Array 题目大意:给出一个数组,每次删除一个数.删除一个数的得分为两边数的最小值,假设左右有一边不存在则算作0分. 问最大得分是多少. ...
- Codeforces Round #504 D. Array Restoration
Codeforces Round #504 D. Array Restoration 题目描述:有一个长度为\(n\)的序列\(a\),有\(q\)次操作,第\(i\)次选择一个区间,将区间里的数全部 ...
随机推荐
- SSH login without password
SSH login without password Your aim You want to use Linux and OpenSSH to automize your tasks. Theref ...
- [Javascript] Replicate JavaScript Constructor Inheritance with Simple Objects (OLOO)
Do you get lost when working with functions and the new keyword? Prototypal inheritance can be compl ...
- codeforces#FF(div2) D DZY Loves Modification
首先要知道选择行列操作时顺序是无关的 用两个数组row[i],col[j]分别表示仅选择i行能得到的最大值和仅选择j列能得到的最大值 这个用优先队列维护,没选择一行(列)后将这行(列)的和减去对应的n ...
- oracle SQL语句(转)
Oracle数据库语句大全 ORACLE支持五种类型的完整性约束 NOT NULL (非空)--防止NULL值进入指定的列,在单列基础上定义,默认情况下,ORACLE允许在任何列中有NULL值. CH ...
- mac下配置eclipse的maven环境
转自:http://www.cnblogs.com/yqskj/archive/2013/03/30/2990292.html 1.下载maven的bin包,解压,配置到环境变量里面去 1). 首先到 ...
- CentOS 6.5 通过 PHP函数的sendmail 发送邮件
非常多站点须要用到Sendmail函数发送激活邮件,在centos中内置了Sendmail模块,直接调用就可以,假设遇到问题,可採用例如以下两个步骤检測并解决: 1. 命令行输入:echo " ...
- node js 安装时选择勾上path
勾上path则会自动配置环境变量,否则必须手动去添加nodejs的环境变量.
- BootLoader与Linux内核的参数传递【转】
本文转载自:http://blog.sina.com.cn/s/blog_476d8cf30100rttx.html 在嵌入式系统中,BootLoader 是用来初始化硬件,加载内核,传递参数.因为嵌 ...
- MYSQL初级学习笔记四:查询数据的操作DQL(SELECT基本形式)(26-35)
知识点六:查询数据的操作DQL(SELECT基本形式)(26-35) CREATE DATABASE IF NOT EXISTS cms DEFAULT CHARACTER SET utf8; USE ...
- java中io类型及成熟io框架
就io本身而言,概念上有5中模型:blocking I/O, nonblocking I/O, I/O multiplexing(select and poll), singal driven I/O ...