http://codeforces.com/problemset/problem/994/B

题意:

给出n和m,有n个骑士,每个骑士的战力为ai,这个骑士有bi的钱,如果一个骑士的战力比另一个骑士的战力高,那么,他就可以夺取这个骑士的钱,但是每个骑士最多夺取m个人,问,这些骑士最多可以获得

多少钱。

 #include <stdio.h>
#include <string.h>
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <sstream>
const int INF=0x3f3f3f3f;
typedef long long LL;
const int mod=1e9+;
//const double PI=acos(-1);
#define Bug cout<<"---------------------"<<endl
const int maxn=1e5+;
using namespace std; struct node
{
int val;
int num;
LL ans;
int pos;
}PE[maxn]; bool cmp1(node a,node b)
{
return a.val<b.val;
} bool cmp2(node a,node b)
{
return a.pos<b.pos;
} int main()
{
int n,m;
scanf("%d %d",&n,&m);
for(int i=;i<=n;i++)
{
scanf("%d",&PE[i].val);
PE[i].pos=i;
}
for(int i=;i<=n;i++)
{
scanf("%d",&PE[i].num);
PE[i].ans=;
}
sort(PE+,PE++n,cmp1);//按战力排序
priority_queue<int,vector<int> ,greater<int> > qe;//存放m个大的硬币数
LL sum=;
for(int i=;i<=n;i++)
{
if(qe.size()<m)
{
qe.push(PE[i].num);
sum+=PE[i].num;
}
else if(!qe.empty())
{
int t=qe.top();
if(t<PE[i].num)
{
qe.pop();
sum=sum-t+PE[i].num;
qe.push(PE[i].num);
}
}
PE[i+].ans+=sum;//注意是i+1
}
sort(PE+,PE++n,cmp2);//按位置排序
for(int i=;i<=n;i++)
{
printf("%lld ",PE[i].ans+PE[i].num);//注意是LL
}
return ;
}

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

  1. Codeforces 994B. Knights of a Polygonal Table

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

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

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

  3. 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 ...

  4. Knights of a Polygonal Table CodeForces - 994B (贪心)

    大意:n个骑士, 每个骑士有战力p, 钱c, 每个骑士可以抢战力比他低的钱, 每个骑士最多抢k次, 对每个骑士求出最大钱数 按战力排序后, 堆维护动态前k大即可 #include <iostre ...

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

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

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

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

  7. POJ 2942 Knights of the Round Table

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

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

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

  9. 【LA3523】 Knights of the Round Table (点双连通分量+染色问题?)

    Being a knight is a very attractive career: searching for the Holy Grail, saving damsels in distress ...

随机推荐

  1. EUI库 - 概述

        新特性 36k   访问EUI组件宽高时,也会跟原生显示对象的表现一致,立即能得到包含子项的宽高值   统一的显示列表  普通对象和eui对象都可用addChild来添加   一个逻辑组件只管 ...

  2. git 公钥 ssh

    1 安装 git 2 桌面右击  Git Bash Here 3 命令: git config --global user.name "git账户" git config --gl ...

  3. bzoj1415 NOI2005聪聪和可可

    %%%http://hzwer.com/2819.html 先各种暴力搞出来p[x][y](从x到y下一个最近应该到达的位子) 然后就记忆化搜索??(雾) #include<bits/stdc+ ...

  4. [转自官方文档] Django——render()

    每个视图都需要做2件事,返回一个包含被请求页面内容的HttpResponse对象或者一个404 快捷函数  render( 请求, 模板, 内容) 载入模板,填充上下文,再返回它生成的HttpResp ...

  5. Nginx负载均衡(转发)

    http://www.cnblogs.com/jalja/p/6117881.html 一.反向代理 正向代理: 客户端要获取的资源就在服务器上,客户端请求的资源路径就是最终响应资源的服务器路径,这就 ...

  6. 支持 UTF-8 中文的串口调试工具

    最近使用 mdk526,编辑设置使用 utf-8,编辑窗口中文正常,但是编译的时候提示 warning: #870-D: invalid multibyte character sequence,解决 ...

  7. PAT 2014 秋

    A 1084 Broken Keyboard 注意大小写即可. #include <cstdio> #include <iostream> #include <algor ...

  8. [CISCN2019 总决赛 Day2 Web1]Easyweb

    0x00 知识点 1:备份文件泄露 2:SQL注入 3:php短标签 短标签<? ?>需要php.ini开启short_open_tag = On,但<?= ?>不受该条控制. ...

  9. convolution in frequency domain

    https://blog.csdn.net/myjiayan/article/details/72427995 convolution in frequency domain convolution ...

  10. CTF密码学常见加密解密总结

    https://blog.csdn.net/qq_40837276/article/details/83080460