Codeforces 1114B (贪心)
题面
分析
答案很好看出,显然是选最大的m*k个数
那么如何构造方案呢
我们把最大的m*k个数的位置标记为1,其他标记为0
从左到右维护一个ptr,记录有标记的数的个数,如果当前有m个有标记的数,则已经找到一个满足条件的区间分界点,break
这样的操作进行k-1次,由于ptr单调递增,时间复杂度为\(O(n)\)
代码
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<map>
#include<algorithm>
#define maxn 200005
using namespace std;
typedef long long ll;
int n,m,k;
struct node{
int x;
int id;
}a[maxn];
int mark[maxn];
int cmp(node a,node b){
return a.x>b.x;
}
vector<int>res;
map<int,int>cnt;
int main(){
scanf("%d %d %d",&n,&m,&k);
for(int i=1;i<=n;i++){
scanf("%d",&a[i].x);
a[i].id=i;
}
sort(a+1,a+1+n,cmp);
ll ans=0;
for(int i=1;i<=m*k;i++){
ans+=a[i].x;
mark[a[i].id]=1;
}
int ptr=1;
for(int i=1;i<k;i++){
int len=0;
while(ptr<=n){
if(mark[ptr]){
len++;
}
if(len==m) break;
ptr++;
}
res.push_back(ptr);
ptr++;
}
printf("%lld\n",ans);
for(int x : res){
printf("%d ",x);
}
}
Codeforces 1114B (贪心)的更多相关文章
- CodeForces - 893D 贪心
http://codeforces.com/problemset/problem/893/D 题意 Recenlty Luba有一张信用卡可用,一开始金额为0,每天早上可以去充任意数量的钱.到了晚上, ...
- Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem D (Codeforces 831D) - 贪心 - 二分答案 - 动态规划
There are n people and k keys on a straight line. Every person wants to get to the office which is l ...
- Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) Problem D (Codeforces 828D) - 贪心
Arkady needs your help again! This time he decided to build his own high-speed Internet exchange poi ...
- CodeForces - 93B(贪心+vector<pair<int,double> >+double 的精度操作
题目链接:http://codeforces.com/problemset/problem/93/B B. End of Exams time limit per test 1 second memo ...
- C - Ordering Pizza CodeForces - 867C 贪心 经典
C - Ordering Pizza CodeForces - 867C C - Ordering Pizza 这个是最难的,一个贪心,很经典,但是我不会,早训结束看了题解才知道怎么贪心的. 这个是先 ...
- Codeforces 570C 贪心
题目:http://codeforces.com/contest/570/problem/C 题意:给你一个字符串,由‘.’和小写字母组成.把两个相邻的‘.’替换成一个‘.’,算一次变换.现在给你一些 ...
- Codeforces 732e [贪心][stl乱搞]
/* 不要低头,不要放弃,不要气馁,不要慌张 题意: 给n个插座,m个电脑.每个插座都有一个电压,每个电脑都有需求电压. 每个插座可以接若干变压器,每个变压器可以使得电压变为x/2上取整. 有无限个变 ...
- Codeforces 721D [贪心]
/* 不要低头,不要放弃,不要气馁,不要慌张. 题意: 给一列数a,可以进行k次操作,每次操作可以选取任意一个数加x或者减x,x是固定的数.求如何才能使得这个数列所有数乘积最小. 思路: 贪心...讨 ...
- CodeForces - 424B (贪心算法)
Megacity Time Limit: 2000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u Submit Sta ...
随机推荐
- Smarty模板引擎模板文件.tpl和.html的区别
在WEB开发中,PHP作为业务逻辑,HTML作为表现逻辑.但是在Smarty一些文档中可以看到模板文件的拓展名是.tpl,而不是.html,其实所谓的.tpl就是.html. 模版文件可以用任意的扩展 ...
- AOS and clustering
原文转载:http://sjakalax.blogspot.com/2010/10/aos-and-clustering.html AOS and clustering hi, There s ...
- iOS10、Chrome、微信7.0无法定位
问题 在做一个项目的时候,需要使用高德地图进行定位,测试的时候没有问题,在微信中打开的时候,无法进行定位,进过查询资料,得知微信升级7.0做了安全限制,然后使用http的定位不能正常使用,有这种限 ...
- liunx-centos-基础命令详解(1) -主要内容来自 —https://www.cnblogs.com/caozy/p/9261224.html
关机:halt/poweroff :立刻关机reboot :立刻重启 shutdown -r now :立刻重启shutdown -h 00:00 :定时重启 now:立刻shutdown -h +n ...
- Java的基本数据类型,以及他们的封装类
基本类型 大小 默认值 封装类 boolean 1 false Boolean byte 1 0 Byte char 2 \u0000(null) Character sh ...
- 【LeetCode】位运算 bit manipulation(共32题)
[78]Subsets 给了一个 distinct 的数组,返回它所有的子集. Example: Input: nums = [,,] Output: [ [], [], [], [,,], [,], ...
- jQuery ajax上传文件实例
jQuery ajax上传文件实例 <form id="form" enctype="multipart/form-data"><input ...
- python字符串前面的u,还有r
以u或U开头的字符串表示unicode字符串 如果你想要用非英语写文本,那么你需要有一个支持Unicode的编辑器.(了解一下unicode和ascll码还有utf-8) u'你好' # ...
- Rabbit给单独的消息设置超时
/** * 发送消息 * @param user */@RequestMapping(value = prefix+"/setRabbitMessage", method = Re ...
- 【leetcode】1081. Smallest Subsequence of Distinct Characters
题目如下: Return the lexicographically smallest subsequence of text that contains all the distinct chara ...