Sicily10359(优先队列)
来源:互联网 发布:雅士尼处理器软件 编辑:程序博客网 时间:2024/06/05 16:38
#include <iostream>#include <cstdio>#include <algorithm>#include <cstring>#include <queue>using namespace std;struct object{ int w,v;}A[300005];int bag[300005];bool cmp1(struct object a,struct object b){ return a.w<b.w;}class cmp2{public: bool operator()(struct object a,struct object b) { return a.v<b.v; }};int main(){ int n,m; int i,j; priority_queue<struct object,vector<struct object>,cmp2> Q; scanf("%d%d",&n,&m); for (i=0;i<n;i++) scanf("%d%d",&A[i].w,&A[i].v); for (i=0;i<m;i++) scanf("%d",&bag[i]); sort(A,A+n,cmp1); sort(bag,bag+m); int Apos=0; long long ans=0; for (i=0;i<m;i++) { while (Apos<n && A[Apos].w<=bag[i]) { Q.push(A[Apos]); Apos++; } if (!Q.empty()) { ans+=Q.top().v; Q.pop(); } } printf("%lld\n",ans);}
0 0
- Sicily10359(优先队列)
- 优先队列
- 优先队列
- 优先队列
- 优先队列
- 优先队列
- 优先队列
- 优先队列
- 优先队列
- 优先队列
- 优先队列
- 优先队列
- 优先队列
- 优先队列
- 优先队列
- 优先队列
- 优先队列
- 优先队列
- 获取电池电量的方法
- UVa:1513 Movie collection
- 人际交流
- python数据结构与算法 6栈的应用之符号平衡(通用)
- 10400 - Game Show Math
- Sicily10359(优先队列)
- POJ 1195 Mobile phones
- LeetCode Best Time to Buy and Sell Stock II
- zoj 2975 Kinds of Fuwas(数学题)
- 12款很棒的浏览器兼容性测试工具推荐
- Handler的使用
- (libgdx学习)compass(指南针)
- 苹果帮助文档
- OllyDBG 入门系列(五)-消息断点及 RUN 跟踪