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 ...
随机推荐
- 第四讲 自定义Realm来实现身份认证
1.jdbcReam已经实现了从数据库中获取用户的验证信息,但是jdbcRealm灵活性太差.如果要实现自己的一些特殊应用时,将不能支持.这时,可以通过自定义Realm来实现身份的认证功能. 2.Re ...
- 【记录】spring boot 全局捕获异常@ExceptionHandler与@Validated @RequestBody 配合使用
@ExceptionHandler与@Validated @RequestBody 三者配合使用可以很好的做到入参校验,具体demo如下: 接口 import org.springframework. ...
- 2019-3-1-C#-json-转-xml-字符串
title author date CreateTime categories C# json 转 xml 字符串 lindexi 2019-03-01 09:20:24 +0800 2019-1-1 ...
- NLP 中 Attention Model 解析
Attention Model,简称AM模型,本文只谈文本领域的AM模型,其实图片领域AM的机制也是相同的. 目前绝大多数文献中出现的AM模型是附着在Encoder-Decoder框架下的,但是其实A ...
- 使用GDB调试时attach ID不被允许
在进入gdb后,直接使用attach ID,出现下面的情况: Could not attach to process. If your uid matches the uid of the targ ...
- 理解uboot过程中的优秀博客
To_run_away的博客 https://blog.csdn.net/qq_16777851/column/info/28098/5 加了微信好友,公众号也有文章. Camus https://c ...
- sqlmap 基本使用步骤(二)
post------------------------------------------------------------------1.使用 -rpython sqlmap.py -r pos ...
- .OnCommand mfc
.OnCommand是响应WM_COMMAND消息的,一般是响应控件和菜单的命令消息时使用. 如果 WM_COMMAND 来自控件的话 lParam 就是发送这个 WM_COMMAND 消息的控件的句 ...
- 前端每日实战:45# 视频演示如何用纯 CSS 创作一个菱形 loader 动画
效果预览 按下右侧的"点击预览"按钮可以在当前页面预览,点击链接可以全屏预览. https://codepen.io/comehope/pen/eKzjqK 可交互视频教程 此视频 ...
- 【leetcode】1053. Previous Permutation With One Swap
题目如下: Given an array A of positive integers (not necessarily distinct), return the lexicographically ...