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 ...
随机推荐
- [小问题笔记(七)] JS和 jQuery常用语句笔记(隐藏/显示/禁用标签 日期操作 跳转等)
隐藏/显示标签 $("#div1").css("display", "none");$("#div2").css(&qu ...
- 使用size_t注意边界
C++中的 size_t 表示数组的下标,一般为: typedef unsigned size_t; 在学习中我们一般使用int表示下标,这样在循环中可以判断边界x>=0 或x<=0,比如 ...
- 在.Net中进行SQL Server数据库备份与还原操作实用类
#region 类说明 //----------------------------------------------------------------------------- // // 项目 ...
- Angular2 中的依赖包详解
转自:http://blog.csdn.net/feiying008/article/details/53033704 目录 dependencies 和 devDependencies depend ...
- 在xampp集成环境下使用 php 连接oracle
今天搞了大半天,终于成功了. 1. 首先需要让xampp支持oracle,直接按这个网页上说的做就行.http://nimal.info/blog/2009/activate-oracle-on-xa ...
- JSP XML 数据处理
JSP XML 数据处理 当通过HTTP发送XML数据时,就有必要使用JSP来处理传入和流出的XML文档了,比如RSS文档.作为一个XML文档,它仅仅只是一堆文本而已,使用JSP创建XML文档并不比创 ...
- poj1228稳定凸包
就是给一系列点,看这是不是一个稳定凸包 稳定凸包是指一个凸包不能通过加点来使它扩大面积,也就是说每条边最少有三个点 判断的地方写错了,写了两边循环,其实数组s已经排好了序,直接每三个判断就好了 #in ...
- UVA-1312 Cricket Field (技巧枚举)
题目大意:在一个w*h的网格中,有n个点,找出一个最大的正方形,使得正方形内部没有点. 题目分析:寻找正方形实质上等同于寻找矩形(只需令长宽同取较短的边长).那么枚举出所有可能的长宽组合取最优答案即可 ...
- hdu 6113 度度熊的01世界(结构体的赋值问题)
题目大意: 输入n*m的字符串矩形,判断里面的图形是1还是0,还是什么都不是 注意:结构体中放赋值函数,结构体仍旧能定义的写法 #include <iostream> #include&l ...
- 转载-lvs官方文档-LVS集群中的IP负载均衡技术
章文嵩(wensong@linux-vs.org) 2002 年 4 月 本文在分析服务器集群实现虚拟网络服务的相关技术上,详细描述了LVS集群中实现的三种IP负载均衡技术(VS/NAT.VS/TUN ...