【Codeforces】Round #538 (Div. 2) 1114B Yet Another Array Partitioning Task(数组+贪心)

14 篇文章 0 订阅
14 篇文章 0 订阅

原题链接:B. Yet Another Array Partitioning Task
在这里插入图片描述在这里插入图片描述
就不贴中文了,我也是直接看英文的

题意

这题题意很简单输入n,m,k
然后输入一组长度为n的序列,要求分成k组,每组的前m个最大值加起来的值要最大

题解

比赛的时候没想打结构体排序,只想着一次sort能不能完事,后来听了队友一顿操作,感受到了自己思路上的不足

#include<bits/stdc++.h>
using namespace std;
int n,m,k,a[200005],id[200005];
long long sum;
bool cmp(int x,int y) {
	return a[x]>a[y];
}
int main() {
	cin>>n>>m>>k;
	int i;
	for(i=1; i<=n; i++) {
		cin>>a[i];
		id[i]=i;
	}
	sort(id+1,id+n+1,cmp);
	for(i=1; i<=m*k; i++)sum+=a[id[i]];
	cout<<sum<<'\n';
	sort(id+1,id+m*k+1);
	for(i=m; i<m*k; i+=m)cout<<id[i]<<" ";
	return 0;
}//By py_ultron, contest: Codeforces Round #538 (Div. 2), problem: (B) Yet Another Array Partitioning Task, Accepted, #
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值