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\)次选择一个区间,将区间里的数全部 ...
随机推荐
- onlyOffice 开发相关 总结
onlyOffice 服务端 客户端 相关开发整理 功能: 所有客户端都可用 云端部署服务 查看 预览 doc ppt excel 编辑 权限控制 开发技术准备 用户服务器端 提供保存接口 用户浏览器 ...
- react 创建组件 (二)component
因为ES6对类和继承有语法级别的支持,所以用ES6创建组件的方式更加优雅,下面是示例: import React from 'react'; class Greeting extends React. ...
- Android开发的环境搭建及HelloWorld的实现
安装JDK和配置Java开发环境 http://www.oracle.com/technetwork/java/javase/downloads/java-se-jdk-7-download-4321 ...
- vs 总结
1.可以通过 视图--->属性管理器 来直接配置opencv,一键搞定 2.按住shift键不放,然后移动方向键,可以选中一路数据点. 3.调试程序的利器,调用堆栈,可以定位到程序死的那一刻. ...
- Android Auto Scroll ViewPager (Smooth)
项目信息 项目地址 https://github.com/benniaobuguai/android-auto-scroll-viewpager 特性 支持自动平滑切换海报.相册等,无限次循环轮播 手 ...
- js 监控浏览器关闭(完美兼容chrome & ie & fire fox)
var UnloadConfirm = {}; UnloadConfirm.MSG_UNLOAD = "数据尚未保存,离开后可能会导致数据丢失\n\n您确定要离开吗?"; Unlo ...
- ISC DHCP: Enterprise grade solution for configuration needs
https://www.isc.org/downloads/dhcp/ ISC DHCP: Enterprise grade solution for configuration needs All ...
- 【ACdream】1157 Segments cdq分治
Segments Problem Description 由3钟类型操作:1)D L R(1 <= L <= R <= 1000000000) 增加一条线段[L,R]2)C i ...
- all rows from client_id can grow infinitely compared to a single node when hashing by client_id
all rows from client_id can grow infinitely compared to a single node when hashing by client_id Re: ...
- compile java sources
Information:javac 1.8.0_91 was used to compile java sources D:\myjdk\bin\java "-javaagent:C:\Pr ...