题目描述

Farmer John has so very many jobs to do! In order to run the farm efficiently, he must make money on the jobs he does, each one of which takes just one time unit.

His work day starts at time 0 and has 1,000,000,000 time units (!). He currently can choose from any of N (1 <= N <= 100,000) jobs

conveniently numbered 1..N for work to do. It is possible but

extremely unlikely that he has time for all N jobs since he can only work on one job during any time unit and the deadlines tend to fall so that he can not perform all the tasks.

Job i has deadline D_i (1 <= D_i <= 1,000,000,000). If he finishes job i by then, he makes a profit of P_i (1 <= P_i <= 1,000,000,000).

What is the maximum total profit that FJ can earn from a given list of jobs and deadlines? The answer might not fit into a 32-bit integer.

约翰有太多的工作要做。为了让农场高效运转,他必须靠他的工作赚钱,每项工作花一个单位时间。 他的工作日从0时刻开始,有1^8个单位时间。在任一时刻,他都可以选择编号1~N的N(1 <= N <= 10^6)项工作中的任意一项工作来完成。 因为他在每个单位时间里只能做一个工作,而每项工作又有一个截止日期,所以他很难有时间完成所有N个工作,虽然还是有可能。 对于第i个工作,有一个截止时间D_i(1 <= D_i <= 10^9),如果他可以完成这个工作,那么他可以获利P_i( 1<=P_i<=10^9 ). 在给定的工作利润和截止时间下,约翰能够获得的利润最大为多少.

输入输出格式

输入格式:

  • Line 1: A single integer: N

  • Lines 2..N+1: Line i+1 contains two space-separated integers: D_i and P_i

输出格式:

  • Line 1: A single number on a line by itself that is the maximum possible profit FJ can earn.

输入输出样例

输入样例#1:

3
2 10
1 5
1 7
输出样例#1:

17

说明

Complete job 3 (1,7) at time 1 and complete job 1 (2,10) at time 2 to maximize the earnings (7 + 10 -> 17).

思路:用一个优先对列进行贪心。

错因:优先队列的优先级是先大后小,我以为是先小后大。

#include<queue>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int n;
long long ans,time;
struct nond{
long long end,val;
}v[];
priority_queue<long long,vector<long long>,greater<long long> >que;
int cmp(nond a,nond b){
return a.end<b.end;
}
int main(){
cin>>n;
for(int i=;i<=n;i++)
cin>>v[i].end>>v[i].val;
sort(v+,v++n,cmp);
for(int i=;i<=n;i++){
if(time<v[i].end){
time++;
ans+=v[i].val;
que.push(v[i].val);
}
else if(time==v[i].end&&que.top()<v[i].val){
ans-=que.top();
ans+=v[i].val;
que.pop();
que.push(v[i].val);
}
}
cout<<ans;
}

最新文章

  1. 执行jar文件生成pdf报错,Unsupported URL &lt;file:///home
  2. scrollview 中嵌套多个listview的最好解决办法
  3. supervisor(二)event
  4. html5文章 -- HTML5开发实例-网易微博手机Web App开发过程
  5. jQuery EasyUI DataGrid Checkbox 数据设定与取值
  6. 【rails3教材】博客构建过程
  7. [jobdu]从尾到头打印链表
  8. 在Eclipse发展Webapp部署过程,缓存的位置
  9. [Unity UGUI]UGUI提供多种不同的解决方案
  10. Python基础之内置函数和递归
  11. java学习笔记之日期日历类
  12. Go基础之--排序和查找操作
  13. 当使用vue的按键修饰符不起效果的时候怎么办?如@keyup.enter = &#39;&#39; ;
  14. Java基础7:关于Java类和包的那些事
  15. WEB的数据交互具体流程
  16. crontab架构和格式
  17. 1.1.19 Word中表格自动断开
  18. python 安装pymssql
  19. python之函数用法setattr(),了解即可
  20. 【OCP-12c】CUUG最新考试原题整理及答案(071-12)

热门文章

  1. ajax短轮询+php与服务器交互制作简易即时聊天网站
  2. Hadoop(2)_机器信息分布表
  3. easy-ui采坑事件
  4. Android获取图片实际大小兼容平板电脑
  5. listView中adapter有不同的click事件的简单写法
  6. 详解Mysql分布式事务XA(跨数据库事务)
  7. Tcl学习之--表达式
  8. layer iframe加载单个图片或者加载页面
  9. HDU 3861--The King’s Problem【scc缩点构图 &amp;amp;&amp;amp; 二分匹配求最小路径覆盖】
  10. 使用Android Studo开发NDK之Gradle的配置(能debug C代码)