Korean War: Bombing size and island

Source: Internet
Author: User

Question Description

In November 1951, the defend volunteers decided to bomb the size and the island in order to withstand the US military's frantic attack. Support Army trained to hit 90%! The size of the U.S. military and the island's facilities were destroyed. Now as most of the U.S. military to fight back to the volunteers, only a repairman, the repairman although driving a car, can arrive instantaneous, but repair or need time, if not timely repair, equipment will be scrapped. and equipment can only be repaired. What sort of repair order can I ask to keep more equipment?

Input
First line: is an integer n
Next n rows: two integers per line t1,t2
It takes T1 minutes to repair the building, if not within T2 minutes.
The building was scrapped when the repairs were completed.
Output
Output an integer s, which means that a maximum of s buildings can be repaired.
Input example
4
100 200
200 1300
1000 1250
2000 3200
Output example
3
Other Notes
Data range: n<15000

C Program:

#include <iostream>#include<cstring>#include<queue>#include<cstdio>#include<algorithm>using namespacestd;Const intn=150006;structBig_heap {inta[n<<1|1], tot; voidInitintN) { for(intI=1; I<= (n<<1|1); i++) a[i]=0; Tot=0; }    voidInsert (intval) {a[++tot]=Val;  for(intX=tot; X>1&& a[x]>a[x>>1]; x>>=1) Swap (a[x], a[x>>1]); }    voidUpdate (intval) {a[1]=Val;  for(intI=1, j=2; j<=tot; I=j, j<<=1) {            if((j|1) <=tot && a[j]<a[j|1]) j|=1; if(A[j]<a[i]) Break;        Swap (A[i], a[j]); }}} heap;structData {intT1, T2; BOOL operator< (ConstData &t)Const {        returnt2<t.t2; }} A[n];intN, ans, cur;intMain () { while(SCANF ("%d", &n)! =EOF) {         for(intI=0; i<n; i++) scanf ("%d%d", &a[i].t1, &a[i].t2); Sort (A, a+N); Cur=ans=0, Heap.init (n);  for(intI=0; i<n; i++) {            if(A[I].T1+CUR&LT;=A[I].T2) ans++, heap. Insert (A[I].T1), cur+=a[i].t1; Else {                if(!heap.tot)Continue; intVal=heap. a[1]; if(VAL&LT;=A[I].T1)Continue; Cur-=val-a[i].t1; Heap.            Update (A[I].T1); }} printf ("%d\n", ans); }    return 0;}

Korean War: Bombing size and island

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.