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的更多相关文章

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

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

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

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

  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. No input file specified. nginx服务器报错解决

    配置虚拟域名的时候报No input file specified. 仔细观察一圈也没有发现任何错误,最终,我把注意力放到 \ 上.才发现问题. 以前我都是直接copy文件路径过去 文件里面 都是使用 ...

  2. Vue——解决[Vue warn]: Invalid prop: custom validator check failed for prop "index". found in错误

    Invalid prop: custom validator check failed for prop "index". 错误重现: 使用element-ui的菜单,在SubMe ...

  3. 贯众云平台脚本编写之判断、循环以及shell命令的使用

    最近使用贯众云平台工具写脚本,进行Ui界面的自动化测试.刚开始接触,确实碰到不少的问题,稍微难点的就是判断语句,循环语句以及shell命令的使用,尤其是对于咱们测试这样比较少接触代码的人来说. 其实吧 ...

  4. UOJ34 多项式乘法(NTT)

    本文版权归ljh2000和博客园共有,欢迎转载,但须保留此声明,并给出原文链接,谢谢合作. 本文作者:ljh2000 作者博客:http://www.cnblogs.com/ljh2000-jump/ ...

  5. vue element new vue const

    new Vue{ el:"app", } ========= const app = new Vue({ router, data:{....} }).$mount('#app') ...

  6. 关于 MongoDB 复制集

    为什么要使用复制集 1.备份数据通过自带的 mongo_dump/mongo_restore 工具也可以实现备份,但是毕竟没有复制集的自动同步备份方便. 2.故障自动转移部署了复制集,当主节点挂了后, ...

  7. Spring MVC:控制器类名称处理映射

    控制器类名称处理映射的好好处是: 如果项目是hello,WelcomeController是控制器,那么访问地址是: http://localhost:8080/hello/welcome http: ...

  8. 《深入理解mybatis原理7》 MyBatis的二级缓存的设计原理

    <深入理解mybatis原理> MyBatis的二级缓存的设计原理 MyBatis的二级缓存是Application级别的缓存,它可以提高对数据库查询的效率,以提高应用的性能.本文将全面分 ...

  9. 3.java内存模型以及happens-before规则

    1. JMM的介绍 在上一篇文章中总结了线程的状态转换和一些基本操作,对多线程已经有一点基本的认识了,如果多线程编程只有这么简单,那我们就不必费劲周折的去学习它了.在多线程中稍微不注意就会出现线程安全 ...

  10. BZOJ 1003 [ZJOI2006]物流运输trans ★(Dijkstra + DP)

    题目链接 http://www.lydsy.com/JudgeOnline/problem.php?id=1003 思路 先Dijkstra暴力求出i..j天内不变换路线的最少花费,然后dp[i] = ...