http://www.lydsy.com/JudgeOnline/problem.php?id=1029
Sort tasks by the cut-off time from small to large
If the current time + current task is time consuming <= the current task deadline, take the task time to put it into the big heap, ans++
Otherwise, if the heap top > Current task is time consuming, delete the top of the heap, and take this task time to the big heap
#include <queue>#include<cstdio>#include<iostream>#include<algorithm>#defineN 150001using namespacestd;structnode{intlen,endd;} E[n];p riority_queue<int>Q;voidReadint&x) {x=0;CharC=GetChar (); while(!isdigit (c)) c=GetChar (); while(IsDigit (c)) {x=x*Ten+c-'0'; C=GetChar (); } }BOOLCMP (node P,node q) {returnp.endd<q.endd;}intMain () {Freopen ("repair.in","R", stdin); Freopen ("Repair.out","W", stdout); intN; Read (n); for(intI=1; i<=n;++i) read (E[i].len), read (E[I].ENDD); Sort (e+1, e+n+1, CMP); Long Longnow=0; intans=0; for(intI=1; i<=n;++i) {if(NOW+E[I].LEN<=E[I].ENDD) Ans++,q.push (E[i].len), now+=E[i].len; Else if(Q.top () >e[i].len) now-=q.top ()-E[i].len,q.pop (), Q.push (E[i].len); } cout<<ans;}
1029: [JSOI2007] Building repair time limit:4 Sec Memory limit:162 MB
submit:5493 solved:2438
[Submit] [Status] [Discuss] 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 Output3
Bzoj thousand project 119:bzoj1029: [JSOI2007] Construction Repair