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. Nginx 从0开始学

    作为一个 nginx 的初学者记录一下从零起步的点滴. 基本概念 Nginx 最常的用途是提供反向代理服务,那么什么反向代理呢?正向代理相信很多大陆同胞都在这片神奇的土地上用过了,原理大致如下图: 代 ...

  2. Cookie和Session的工作原理及比较

    一.Cookie详解 (1)简介 因为HTTP协议是无状态的,即服务器不知道用户上一次做了什么,这严重阻碍了交互式Web应用程序的实现.在典型的网上购物场景中,用户浏览了几个页面,买了一盒饼干和两饮料 ...

  3. linux修改系统时间时区

    修改时间: date -s "2017-08-10 17:00:00" clock -w 修改时区: 方法一: ln -sf /usr/share/zoneinfo/Asia/Sh ...

  4. POJ 3167 Cow Pattern ★(KMP好题)

    题意 给你一个数字序列S,再给一个数字序列pattern,S和pattern中的数字都是1到s(s<=25).每个序列里的数字都有个排名,也就是第几小,现在我们要用pattern来匹配S.在本题 ...

  5. 卸载Linux自带的JDK

    Redhat Enterprise Linux中自带了jdk的旧版本,往往需要卸载,卸载步骤如下: 在终端输入:yum remove java 终端显示:Is this ok[y/N]: 输入y,按回 ...

  6. js排序算法03——选择排序

    选排序的思路是首先从要排序的数组中选择最小的和目前的第一位交换位置,然后从剩下的数中选择最小的和第二个位置的数交换位置,再从剩下的数中选择最小的和第三个位置的数交换位置,以此类推,实现代码如下: fu ...

  7. echarts 折线图配置

    html内容: <div id="user_num_chart" style="width: 582px;height:250px;"></d ...

  8. Django开发BUG "Model class WH_auth.models.User doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS."

    当进行数据库迁移的时候发生问题,报错如下:RuntimeError: Model class WH_auth.models.User doesn't declare an explicit app_l ...

  9. laravel中新建文件并保存数据到文件中

    //base_path()获取当前的绝对路径 $path=base_path().'\config\web.php'; $str='abcdefg'; //要声明的字符串 file_put_conte ...

  10. LNMP的搭建与原理

    常见的web框架结构:例如:lnmp和:ampL=LINUX N=NGINX A=APACHE P=php T=Tomcat lnmp的原理 在LNMP组合工作时,首先是用户通过浏览器输入域名请求Ng ...