A greedy one, maintaining a state that is as good as possible (i.e. no better than the optimal escorted), and keeping this state to the last.
1 /**************************************************************2 problem:10293 user:idy0024 language:c++5 result:accepted6 time:400 Ms7 memory:2368 KB8 ****************************************************************/9 Ten#include <cstdio> One#include <queue> A#include <algorithm> - #defineMAXN 150010 - using namespacestd; the - intN, CNT, CTM; -priority_queue<int>Heap; - + structPair { - intT1, T2; + BOOL operator< (ConstPair & B)Const { A returnt2<b.t2; at } - }; - Pair JOBS[MAXN]; - - intMain () { -scanf"%d", &n); in for(intI=1; i<=n; i++ ) -scanf"%d%d", &jobs[i].t1, &jobs[i].t2); toSort (jobs+1, jobs+1+n); +CNT = CTM =0; - for(intI=1; i<=n; i++ ) { the if(JOBS[I].T1+CTM <=jobs[i].t2) { * Heap.push (JOBS[I].T1); $cnt++;Panax NotoginsengCTM + =jobs[i].t1; -}Else { the if(Jobs[i].t1 <Heap.top ()) { +cnt--; ACTM-=heap.top (); the Heap.pop (); + Heap.push (JOBS[I].T1); -cnt++; $CTM + =jobs[i].t1; $ } - } - } theprintf"%d\n", CNT); -}View Code
Bzoj 1029 Greed