Description
Farmer John has too much work to do,!!!!!!!!. In order for the farm to run efficiently, he had to make money from his work and spend a unit of time on every job. His workday starts from 0 hours and has 1 billion units of time (!). )。 At any one time, he can select any of the 1~n's n (1 <= n <= 100000) jobs to complete. Because he can only do one job per unit of time, and each job has a deadline, so it is difficult for him to have time to complete all the n jobs, although it is still possible. For the I work, there is a cutoff time of d_i (1 <= d_i <= 1000000000), and if he can finish the job then he can make a profit p_i (1<=p_i<=1000000000). What is the maximum profit a FJ can earn under a given job profit and cut-off time? The answer may exceed the 32-bit integer type.
Input
Line 1th: an integer n. Line 2~n+1: line i+1 has two integers separated by a space: D_i and P_i.
Output
The output line has an integer representing the maximum profit value.
Sample Input3
2 10
1 5
1 7
Sample Output17
HINT
The 1th unit time completes the 3rd work (1,7), then completes the 1th work (2,10) in the 2nd unit time to achieve the maximum profit
Problem solving: It is also a relatively simple question, obviously we want to fill up the 0-n, then according to the DDL from small to large order, if 0 to the work of the DDL is still empty, the current work of course to add, if not empty, obviously to replace the previous work of the least profit, Then it is natural to think of using heaps to maintain this minimal benefit.
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <queue>5#include <algorithm>6 #defineMAXN 1000097 using namespacestd;8 structT9 {Ten Long Longx; One Long Longy; A }A[MAXN]; - intcmp (T x,t y) - { the returnx.x <y.x; - } - intMain () - { + intN; - Long Longans=0; +scanf"%d",&n); A for(intI=1; i<=n;i++) at { -scanf"%lld%lld",&a[i].x,&a[i].y); - } -Sort (A +1, A +1+n,cmp); -priority_queue<Long Long,vector<Long Long>,greater<Long Long> >Q; - for(intI=1; i<=n;i++) in { - intU =q.size (); to if(U <a[i].x) Q.push (A[I].Y); + Else - { the intv =q.top (); * if(V <a[i].y) $ {Panax Notoginseng Q.pop (); - Q.push (A[I].Y); the } + } A } the while(!q.empty ()) + { -Ans + =q.top (); $ Q.pop (); $ } -printf"%lld\n", ans); - return 0; the}
Bzoj 1572: [Usaco2009 Open] work schedule Job