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 ;
}

最新文章

  1. [Erlang 0122] Erlang Resources 2014年1月~6月资讯合集
  2. java内存泄露
  3. HTTP基础05--http首部
  4. Control Flow
  5. oracle数据库的乱码问题解决方案
  6. Red Hat Linux9命令行--修改补充中
  7. Android事件传递机制(转)
  8. 实现IDisposable接口的模式
  9. Python中的两种列表
  10. ASCII和16进制
  11. java 的开源wiki维基系统
  12. DataTable举例
  13. C#操作Xml:XSLT语法 在.net中使用XSLT转换xml文档示例
  14. 17 个 tar 命令实用示例【转】
  15. sql2005数据库置疑修复断电崩溃索引损坏 数据库索引错误修复/数据库表损坏/索引损坏/系统表混乱等问题修复
  16. 哇,快看,那里有React Native的坑
  17. 学习linux—— VMware 安装 ubantu 18 如何连接wifi
  18. Code Review —— by12061154Joy
  19. t-SNE 聚类
  20. DIV+CSS布局时, DIV的高度和宽度特性

热门文章

  1. windows Driver 查询指定键值
  2. css div框加小箭头
  3. 删除所有的docker容器和镜像(转载)
  4. POJ 2014:Flow Layout 模拟水题
  5. 使用NtQueryInformationFile函数获得不到完整路径
  6. Ubuntu无法锁定管理目录(/var/lib/dpkg/),是否有其他进程正占用它?
  7. 通过Android的API对Sqlite数据库进行操作
  8. maven中的groupId和artifactId 区分
  9. SDWebImage清理缓存
  10. POJ 2528 Mayor‘s poster 线段树+离散化