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. 13 ~ express ~ 后台页面的搭建

    一, 后台路由文件  /router/admin.js  var express = require('express') var router = express.Router() /** * 验证 ...

  2. Charles中windows版本解决response乱码问题

    实际上三种,目前写了两种,加了之后有的不显示乱码,但是有的还是显示,第三种搜索结果是安装证书,但是本人安装后证书后未受到信任,所以暂时不知是否能够成功 1,在charles.ini中,手动增加一个vm ...

  3. poj_3461 KMP算法解析

    A - Oulipo Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit S ...

  4. Java中String类为什么被设计为final?

    Java中String类为什么被设计为final   首先,String是引用类型,也就是每个字符串都是一个String实例.通过源码可以看到String底层维护了一个byte数组:private f ...

  5. 网格视图GridView

    1.常用属性 2.Adapter接口 3.Demo演示 今天观看了GridView的相关视频,并且根据案例,进行了代码的编写和实例 新建GridViewActivity.java继承AppCompat ...

  6. solr8.0.0基本安装和在springboot中的基本使用(win10)

    1.下载solr 下载地址:http://archive.apache.org/dist/lucene/solr/ 该地址可以也可以下载以前的版本,我这边下载的solr-8.0.0.zip版本.下载完 ...

  7. Cracking Digital VLSI Verification Interview 第二章

    Computer Architecture 对Cracking Digital VLSI Verification Interview:Interview Success这本书的汉化,最新更新请关注微 ...

  8. fastreport小入门

    unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms ...

  9. SQL基础教程(第2版)第7章 集合运算:练习题

    可能有些读者会对此感到惊讶:“同时使用 UNION 和 INTERSECT 时,不是 INTERSECT 会优先执行吗?”当然,从执行顺序上来说确实是从 INTERSECT 开始的, 但是在此之前,由 ...

  10. docker 批量命令

    docker中 启动所有的容器命令: docker start $(docker ps -a | awk '{ print $1}' | tail -n +2) docker中    关闭所有的容器命 ...