Bzoj 1029: [JSOI2007] Construction Repair

Source: Internet
Author: User

Description

Xiao Gang is playing a computer game called "Building Repair" provided by Jsoi: After a fierce battle, the T tribe wiped out all the Z tribes
Intruders. But there are already n construction facilities in the T tribe's base that have been severely damaged, and if not repaired soon, the construction facilities will be completely
Destroy. Now the situation is: there is only one repairman at the base of the T tribe, although he can get to any building in an instant, but repairing each building requires
To a certain time. At the same time, the repairman repaired a building to repair the next building, unable to repair multiple buildings at the same time. If a building is in a
The building was scrapped when it was not completely repaired within a period of time. Your task is to help small just rationalize a repair sequence to repair as much
of buildings.

Input

The first line is an integer n the next n rows of two integers per line t1,t2 describe a building: repairing the building takes T1 seconds, and if it's within T2 seconds
Without the repair, the building was scrapped.

Output

Output an integer s, which means that a maximum of s buildings can be repaired. N < 150,000; T1 < T2 < Maxlongint

Sample Input4
100 200
200 1300
1000 1250
3200Sample Output3Hintsource

According to this kind of thinking to go on, sooner or later AFO, encounter greedy problem hang rotten

Too ashamed, basically is to use the heap to adjust the greedy after the order, because the pile in front of the repair is not affected, and then is to let the impact of the back as small as possible;

Made by qt666#include<cstdio> #include <algorithm> #include <cmath> #include <iostream># Include<cstring> #include <queue>using namespace std;typedef long long ll;const int N=300050;int gi () {int x=0  , flag=1;  Char Ch=getchar (); while (ch< ' 0 ' | |  Ch> ' 9 ') {if (ch== '-') Flag=-1;ch=getchar ();}  while (ch>= ' 0 ' &&ch<= ' 9 ') x=x*10+ch-' 0 ', Ch=getchar (); return X*flag;} struct data{int t1,t2;}  House[n];bool CMP (const data &AMP;A,CONST data &b) {if (A.T2==B.T2) return a.t1<b.t1; else return a.t2<b.t2;}  Priority_queue<int>q;int Main () {int n=gi ();  for (int i=1;i<=n;i++) {House[i].t1=gi (), House[i].t2=gi ();  } sort (house+1,house+1+n,cmp);  Q.push (house[1].t1); int ans=1,time=house[1].t1;      for (int i=2;i<=n;i++) {if (time+house[i].t1<=house[i].t2) {ans++;time+=house[i].t1;    Q.push (HOUSE[I].T1);      } else{int max=q.top ();      if (House[i].t1<max) {time=time-max+house[i].t1;q.pop (); Q.push (HOUSE[I].T1); }   }} printf ("%d\n", ans); return 0;}

Bzoj 1029: [JSOI2007] Construction Repair

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.