CodeForces 994B Knights of a Polygonal Table(STL、贪心)
2024-09-07 06:36:27
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 ;
}
最新文章
- [Erlang 0122] Erlang Resources 2014年1月~6月资讯合集
- java内存泄露
- HTTP基础05--http首部
- Control Flow
- oracle数据库的乱码问题解决方案
- Red Hat Linux9命令行--修改补充中
- Android事件传递机制(转)
- 实现IDisposable接口的模式
- Python中的两种列表
- ASCII和16进制
- java 的开源wiki维基系统
- DataTable举例
- C#操作Xml:XSLT语法 在.net中使用XSLT转换xml文档示例
- 17 个 tar 命令实用示例【转】
- sql2005数据库置疑修复断电崩溃索引损坏 数据库索引错误修复/数据库表损坏/索引损坏/系统表混乱等问题修复
- 哇,快看,那里有React Native的坑
- 学习linux—— VMware 安装 ubantu 18 如何连接wifi
- Code Review —— by12061154Joy
- t-SNE 聚类
- DIV+CSS布局时, DIV的高度和宽度特性
热门文章
- windows Driver 查询指定键值
- css div框加小箭头
- 删除所有的docker容器和镜像(转载)
- POJ 2014:Flow Layout 模拟水题
- 使用NtQueryInformationFile函数获得不到完整路径
- Ubuntu无法锁定管理目录(/var/lib/dpkg/),是否有其他进程正占用它?
- 通过Android的API对Sqlite数据库进行操作
- maven中的groupId和artifactId 区分
- SDWebImage清理缓存
- POJ 2528 Mayor‘s poster 线段树+离散化