Bzoj 1029 Greed

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.