CF1114B Yet Another Array Partitioning Task
CF1114B Yet Another Array Partitioning Task
- 贪心,选择前 \(k*m\) 大的元素对答案进行贡献.
- 每次划分时,从当前位置往后扫,扫到 \(m\) 个前 \(k*m\) 大的元素时就将该区间划出.
- 时间复杂度为排序时间复杂度 \(O(nlogn)\) .
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pii pair<int,int>
inline int read()
{
int x=0;
bool pos=1;
char ch=getchar();
for(;!isdigit(ch);ch=getchar())
if(ch=='-')
pos=0;
for(;isdigit(ch);ch=getchar())
x=x*10+ch-'0';
return pos?x:-x;
}
const int MAXN=2e5+10;
int n,m,k;
int a[MAXN];
struct nd{
int x,y;
}b[MAXN];
int cmp(nd x,nd y)
{
return x.x==y.x?x.y<y.y:x.x>y.x;
}
int c[MAXN],tp;
ll ans=0;
bool tag[MAXN];
int stk[MAXN];
int main()
{
n=read(),m=read(),k=read();
for(int i=1;i<=n;++i)
{
a[i]=read();
b[i].x=a[i],b[i].y=i;
}
sort(b+1,b+1+n,cmp);
for(int i=1;i<=k*m;++i)
tag[b[i].y]=1;
int j=0;
for(int i=1;i<=k;++i)
{
int oj=j;
int L=oj+1,R=n-m*(k-i);
int p;
int cnt=0;
for(j=L;j<=R;j++)
{
if(tag[j])
++cnt,ans+=a[j];
if(cnt==m)
break;
}
stk[i]=j;
}
cout<<ans<<endl;
for(int i=1;i<k;++i)
printf("%d ",stk[i]);
return 0;
}
CF1114B Yet Another Array Partitioning Task的更多相关文章
- CF1114B Yet Another Array Partitioning Task(贪心,构造题)
我至今不敢相信我被这么一道简单的题卡了这么久……看来还是太弱了…… 题目链接:CF原网 题目大意:定义一个序列的“美丽度”为这个序列前 $m$ 大的数的和.现在有一个长度为 $n$ 的序列,你需要把它 ...
- 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 ...
- 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 ...
- 【Codeforces 1114B】Yet Another Array Partitioning Task
[链接] 我是链接,点我呀:) [题意] 让你把数组分成k个连续的部分 使得每个部分最大的m个数字的和最大 [题解] 把原数组降序排序 然后选取前m*k个数字打标记 然后对于原数组 一直贪心地取 直到 ...
- Codeforces - 1114B - Yet Another Array Partitioning Task - 构造 - 排序
https://codeforces.com/contest/1114/problem/B 一开始叫我做,我是不会做的,我没发现这个性质. 其实应该很好想才对,至少要选m个元素,其中m个作为最大值,从 ...
- codeforces-473D Mahmoud and Ehab and another array construction task (素数筛法+贪心)
题目传送门 题目大意:先提供一个数组,让你造一个数组,这个数组的要求是 1 各元素之间都互质 2 字典序大于等于原数组 3 每一个元素都大于2 思路: 1.两个数互质的意思就是没有公因子.所以每 ...
- Codeforces 959D. Mahmoud and Ehab and another array construction task(构造, 简单数论)
Codeforces 959D. Mahmoud and Ehab and another array construction task 题意 构造一个任意两个数都互质的序列,使其字典序大等于a序列 ...
- D. Mahmoud and Ehab and another array construction task 因子分界模板+贪心+数学
D. Mahmoud and Ehab and another array construction task 因子分解模板 题意 给出一个原序列a 找出一个字典序大于a的序列b,使得任意 \(i!= ...
- 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 ...
随机推荐
- pathway一些网站
1.BioCarta_Pathways https://cgap.nci.nih.gov/Pathways/BioCarta_Pathways
- Vue 备
<div id="app"> <span :class='{red:addClass}'>jam</span> </div> < ...
- SQL生成两个时间之间的所有日期
select dateadd(dd,number,'2012-1-1') AS date from master..spt_values where type='p' and dateadd(dd,n ...
- 推荐给开发者的11个PHP框架(转)
PHP框架对于Web开发者来说是非常有用的工具,它可以帮助使用者更快.更容易的完成项目.根据调查,PHP仍是Web开发中最受欢迎和最实用的平台之一.当谈及Web开发时,很多人依然会选择使用PHP框架, ...
- 值得推荐的10本PHP书籍(转)
值得推荐的10本PHP书籍(转) 一.总结 一句话总结: 二.值得推荐的10本PHP书籍 本篇文章的目的是想较全面地推荐10本PHP书籍,暂不讨论Linux/NGINX/Mysql等其他丛书. 前言 ...
- Sql Server 2008 清理日志文件
Use LingZhong Select NAME,size From sys.database_files ALTER DATABASE LingZhong SET RECOVERY SIMPLE ...
- 这真是奇葩的js题目
url:http://javascript-puzzlers.herokuapp.com/ 有兴趣的可以一看,算是比较偏门自我感觉
- mysql 在创建表或者插入时遇到关键字报错
mysql 在创建表或者插入时遇到关键字:比如name,status等.都不报错 解决方法:在字段上加上` 上面这个符号是键盘ecs下面那个符号
- iOS 数组集合操作(交集,并集,差集,子集)
1.求数组的 交集,并集,差集 NSArray *array1 = @[@"1",@"2",@"3"]; NSArray *array2 = ...
- Javascript-- jQuery动画篇(淡入淡出效果)
淡入淡出效果 jQuery 提供了下面几种方法可以实现显示的淡入淡出效果: fadeIn() fadeOut() fadeToggle() fadeTo() fadeIn()方法 fadeIn()实现 ...