1572: [Usaco2009 Open]工作安排Job

来源:互联网 发布:电子商务网络平台技术 编辑:程序博客网 时间:2024/05/21 17:33

1572: [Usaco2009 Open]工作安排Job

Time Limit: 10 Sec  Memory Limit: 64 MB
Submit: 1064  Solved: 474
[Submit][Status][Discuss]

Description

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

Input

第1行:一个整数N. 第2~N+1行:第i+1行有两个用空格分开的整数:D_i和P_i.

Output

输出一行,里面有一个整数,表示最大获利值。

Sample Input

3
2 10
1 5
1 7

Sample Output

17

HINT

第1个单位时间完成第3个工作(1,7),然后在第2个单位时间完成第1个工作(2,10)以达到最大利润

Source

Gold

[Submit][Status][Discuss]


贪心,注意边界


#include<iostream>#include<cstdio>#include<cstdlib>#include<algorithm>#include<cstring>#include<cmath>#include<vector>#include<queue>using namespace std;const int maxn = 1E5 + 10;typedef long long LL;struct data{int t,w;bool operator < (const data &b) const {return t < b.t;}}a[maxn];priority_queue<int> q;int n;LL ans;int main(){#ifdef YZY   freopen("yzy.txt","r",stdin);#endifcin >> n;for (int i = 1; i <= n; i++) scanf("%d%d",&a[i].t,&a[i].w);sort(a + 1,a + n + 1);int po = n,ti = 1000000000;while (po) {ti = a[po].t; q.push(a[po--].w);while (a[po].t == a[po+1].t) q.push(a[po--].w);while (!q.empty() && ti > a[po].t) ans += 1LL*q.top(),q.pop(),--ti;}cout << ans;return 0;}


0 0
原创粉丝点击