大意: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. 数据仓库原理<4>:联机分析处理(OLAP)

    本文转载自:http://www.cnblogs.com/hbsygfz/p/4762085.html 1. 引言 本篇主要介绍数据仓库中的一项重要分析技术——联系分析处理(OLAP). 在第一篇笔者 ...

  2. iOS之第三方库以及XCode插件介绍

    前言 第三方库是现在的程序员离不开的东西 不光是APP开发 基本上所有的商业项目 都会或多或少的使用到第三方库 Github上Star>100的开源库数量如下 可以看到JS以绝对的优势排名第一 ...

  3. SNMP学习笔记之Centos7配置SNMP服务

    0x00 安装yum源安装SNMP软件包 1.yum源安装SNMP服务: yum -y install net-snmp net-snmp-utils 2.查看SNMP版本号: snmpd -v 0x ...

  4. Duilib初级控件扩展一例: 具有鼠标滚动消息的OptionUI

    转载:http://www.cnblogs.com/memset/p/Duilib_MouseWheelOptionUI_Deprecated.html

  5. VC++禁止标题栏鼠标双击事件

    转载:http://blog.sina.com.cn/s/blog_4ad042e50102dwv0.html 重载DefWindowProc,在里面截获WM_NCLBUTTONDBLCLK消息进行处 ...

  6. Python3基础 pickle.dump和load 对一个对象进行序列化存储及读取

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  7. 乘积尾零|2018年蓝桥杯B组题解析第三题-fishers

    标题:乘积尾零 如下的10行数据,每行有10个整数,请你求出它们的乘积的末尾有多少个零? 5650 4542 3554 473 946 4114 3871 9073 90 4329 2758 7949 ...

  8. 导出数据库表为world文档说明,以及PowerDesigner导出表结构pdm设计文档

    如何使用“mysql导出数据库结构为world工具”以及如何使用powerdesigner映射数据库模型 一.通过powerdesigner配置ojdbc 1.安装并打开powerdesigner,新 ...

  9. 【第二十九章】 springboot + zipkin + mysql

    zipkin的数据存储可以存在4个地方: 内存(仅用于测试,数据不会持久化,zipkin-server关掉,数据就没有了) 这也是之前使用的 mysql 可能是最熟悉的方式 es Cassandra ...

  10. BZOJ3942: [Usaco2015 Feb]Censoring 栈+KMP

    Description Farmer John has purchased a subscription to Good Hooveskeeping magazine for his cows, so ...