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. codevs 1085 数字游戏 dp或者暴搜

    1085 数字游戏 2003年NOIP全国联赛普及组  时间限制: 1 s  空间限制: 128000 KB     题目描述 Description 丁丁最近沉迷于一个数字游戏之中.这个游戏看似简单 ...

  2. 一些putty的应用设置

    把windows下putty的key转换成linux上使用的rsa key    http://ask.apelearn.com/question/937 putty生成的密钥导入connectbot ...

  3. springboot统一异常处理及返回数据的处理

    一.返回code数据的处理 代码: Result.java /** * http请求返回的最外层对象 * Created by 廖师兄 * 2017-01-21 13:34 */ public cla ...

  4. web项目整合Shiro框架

    1.修改pom.xml文件 <dependency> <groupId>org.apache.shiro</groupId> <artifactId>s ...

  5. 转载:Javascript面向对象编程原理 -- 理解对象

    源地址:http://www.html-js.com/article/1717 虽然JavaScript中已经自带了很多内建引用类型,你还是会很频繁的需要创建自己的对象.JavaScript编程的很大 ...

  6. Django之model字段操作

    # -*- coding: utf-8 -*- from __future__ import unicode_literals from django.db import models import ...

  7. C# RedisRateLimiter

    public class RedisRateLimiter { private static Logger LOG = LogManager.GetLogger("redis-limiter ...

  8. .pth 文件扩展python环境路径

    有时候我们不希望把一个库放到 site-packages 下面,而是更愿意把它保留在原始的工程目录中,方便管理和维护. 通常的做法是在程序启动的时候,往sys.path里面增加这个目录,但是这样做非常 ...

  9. Python -- 使用pickle 和 CPickle对数据对象进行归档和解析

    经常遇到在Python程序运行中得到了一些字符串.列表.字典.对象等数据,想要长久的保存下来,方便以后使用,而不是简单的放入内存中关机断电就丢失数据. 这个时候Pickle模块就派上用场了,它可以将对 ...

  10. ADO.NET简介

    一.ADO.NET ADO.NET源起ADO(ActiveX Data Objects),是一个COM组件库,在NET编程环境中优先使用的数据访问接口, 提供对诸如 SQL Server 和 XML ...