大意:n个骑士, 每个骑士有战力p, 钱c, 每个骑士可以抢战力比他低的钱, 每个骑士最多抢k次, 对每个骑士求出最大钱数

按战力排序后, 堆维护动态前k大即可

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <queue>
#define REP(i,a,n) for(int i=a;i<=n;++i)
using namespace std;
typedef long long ll; const int N = 2e5+10;
int n, m, k;
ll sum, a[N];
struct _ {int p, c, id;}q[N]; priority_queue<int,vector<int>,greater<int> > s; int main() {
s.push(0x7fffffff);
scanf("%d%d", &n, &k);
REP(i,1,n) scanf("%d",&q[i].p),q[i].id=i;
REP(i,1,n) scanf("%d",&q[i].c);
sort(q+1,q+1+n,[](_ a,_ b) {return a.p<b.p;});
REP(i,1,n) {
a[q[i].id] = sum+q[i].c;
if (s.size()<=k) s.push(q[i].c),sum+=q[i].c;
else if (s.top()<q[i].c) {
sum += q[i].c-s.top();
s.pop();s.push(q[i].c);
}
}
REP(i,1,n) printf("%lld ", a[i]);
puts("");
}

Knights of a Polygonal Table CodeForces - 994B (贪心)的更多相关文章

  1. CF994B Knights of a Polygonal Table 第一道 贪心 set/multiset的用法

    Knights of a Polygonal Table time limit per test 1 second memory limit per test 256 megabytes input ...

  2. [C++]Knights of a Polygonal Table(骑士的多角桌)

    [程序结果:用例未完全通过,本博文仅为暂存代码之目的] /* B. Knights of a Polygonal Table url:http://codeforces.com/problemset/ ...

  3. CodeForces 994B Knights of a Polygonal Table(STL、贪心)

    http://codeforces.com/problemset/problem/994/B 题意: 给出n和m,有n个骑士,每个骑士的战力为ai,这个骑士有bi的钱,如果一个骑士的战力比另一个骑士的 ...

  4. Codeforces 994B. Knights of a Polygonal Table

    解题思路 将骑士按力量从小到大排序,到第i个骑士的时候,前面的i-1个骑士他都可以击败,找出金币最多的k个. 用multiset存金币最多的k个骑士的金币数,如果多余k个,则删除金币数最小的,直到只有 ...

  5. [CF994B] Knights of a Polygonal Table - 贪心,堆

    有 n 个骑士想决战.每个骑士都有能力值(互不相同),且身上带有一些金币.如果骑士 A 的能力值大于骑士 B ,那么骑士 A 就可以杀死骑士 B ,并获得骑士 B 身上的所有金币.但就算是骑士也不会残 ...

  6. Arthur and Table CodeForces - 557C

    Arthur and Table CodeForces - 557C 首先,按长度排序. 长度为p的桌腿有a[p]个. 要使得长度为p的桌腿为最长,那么要按照代价从小到大砍掉sum{长度不到p的腿的数 ...

  7. POJ2942 Knights of the Round Table[点双连通分量|二分图染色|补图]

    Knights of the Round Table Time Limit: 7000MS   Memory Limit: 65536K Total Submissions: 12439   Acce ...

  8. POJ 2942 Knights of the Round Table

    Knights of the Round Table Time Limit: 7000MS   Memory Limit: 65536K Total Submissions: 10911   Acce ...

  9. poj 2942 Knights of the Round Table 圆桌骑士(双连通分量模板题)

    Knights of the Round Table Time Limit: 7000MS   Memory Limit: 65536K Total Submissions: 9169   Accep ...

随机推荐

  1. MATLAB 简明教程

    MATAB 是我学习和接触的第一种工具类的编程语言,最早可以追溯到大一上数学分析这门课的时候.MATLAB既是一种软件也是一门编程语言,MATLAB功能强大在理科和工科中运用较多. MATLAB 是 ...

  2. ACM题目————Sunscreen

    Description To avoid unsightly burns while tanning, each of the C (1 ≤ C ≤ 2500) cows must cover her ...

  3. ELK学习笔记之Logstash和Filebeat解析对java异常堆栈下多行日志配置支持

    0x00 概述 logstash官方最新文档.假设有几十台服务器,每台服务器要监控系统日志syslog.tomcat日志.nginx日志.mysql日志等等,监控OOM.内存低下进程被kill.ngi ...

  4. 20145101 《Java程序设计》第7周学习总结

    20145101<Java程序设计>第7周学习总结 教材学习内容总结 第十二章 Lambda Lambda表达式中this的参考对象以及toString()的接受者,是来自Lambda的周 ...

  5. CSAPP 第三章 读书笔记

    程序的机器级表示 AT&T与Intel格式的汇编代码 我们的表述是ATT(根据"AT&T"命名的, AT&T是运营贝尔实验室多年的公 司)格式的汇编代码,这 ...

  6. STM32系统时钟为什么没有定义呢

    对于使用3.5版本库开发的STM32学习者 有时候不清楚为什么没有时钟定义 那么我们就简单的讲解下吧: 1,函数从启动文件开始运行(汇编文件) 2,若是hd.s 请看151行LDR     R0, = ...

  7. NRF24L01通信频率

    RF-CH 共包括六位,这六位决定了不同的工作方式频率,nRF24L01无线通信模块中工作通道频率由RF-CH寄存器的内容确定, 可由以下公式计算得出:Fo=(2400+RF-CH)MHz. 扩展:射 ...

  8. visual studio扩展插件Visual Assist x给代码插入注释模板(转载)

    转载:http://www.cnblogs.com/xiongmao-cpp/p/5196555.html Visual Assist 是由Whole Tomato公司为Microsoft Visua ...

  9. Android学习笔记之 ActionBar

    http://developer.android.com/guide/topics/ui/actionbar.html 1,ActionBar的几种形式 2,使用ActionBar需要Activity ...

  10. 浅入浅出JS中的eval及json

    声明: 首先声明一下,本人是JS新手,所以不敢说深入,只是把最近对eval的学习经验拿出来跟大家分享,如果您是高手可略去不看. 适合读者: 对JS中的eval一知半解,不知eval是如何把字符串转换为 ...