1029: [JSOI2007] Construction repair Time limit:4 Sec Memory limit:162 MB
Topic Connection
http://www.lydsy.com/JudgeOnline/problem.php?id=1029
Description is playing a computer game called "Building Repair" that Jsoi offers: After a fierce battle, the T tribe wiped out all the invaders of the Z tribe. 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 destroyed. 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 will take some 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 has not been completely repaired for a period of time, the building will be scrapped. Your mission is to help small just make a reasonable order of repairs to repair as many buildings as possible. The first line of input is an integer n, and the next n rows of two integers per line t1,t2 describe a building: it takes T1 seconds to repair the building, and if it is not repaired within T2 seconds, the building is scrapped. Output Output An integer s, which means that a maximum of s buildings can be repaired. Data range: N<150000,T1
Sample Input4
100 200
200 1300
1000 1250
2000 3200
Sample Output3
HINT
Exercises
Sort by end time first
With a big pile, throw in every possible thing, and if something doesn't work out, then we'll compare the time spent on it with the first one in Dagen.
If it takes less time than he does, then it must be a substitute for that thing.
It's pretty easy to prove, but it's clear to think.
Code:
//Qscqesze#include <cstdio>#include <cmath>#include <cstring>#include <ctime>#include <iostream>#include <algorithm>#include <Set>#include <vector>#include <sstream>#include <queue>#include <typeinfo>#include <fstream>#include <map>typedefLongLongllUsingNamespaceStd//Freopen ("D.in", "R", stdin);//Freopen ("D.out", "w", stdout);#define Sspeed ios_base::sync_with_stdio (0); Cin.tie (0)#define MAXN 200001#define MOD 10007#define EPS 1e-9//const int INF=0X7FFFFFFF;//Infinitely largeConstint inf=0x3f3f3f3f;/**///**************************************************************************************inline ll read () {int x=0,f=1;Char ch=GetChar ();while (ch<‘0' | | Ch>‘9‘){if (ch==‘-') f=-1;ch=GetChar ();}while (ch>=‘0' &&ch<=‘9') {x=x*10+ch-‘0'; ch=GetChar ();}Return x*F;}structnode{Intx, y;};boolCMP (node A,node b) {Return a.y<B.Y;} Node A[MAXN];p riority_queue<Int>QIntMain () {IntN Cin>>NForint i=0;i<n;i++) A[i].x=read (), a[i].y=Read (); Sort (a,a+N,CMP);int now=0; int ans=0; For (int i=0;i<n;i++) { if (now+a[i].x<=a[i].y) {ans++; now+=a[i].x; Q.push (a[ i].x); } else { int h=q.top (); if (a[i].x<h) {q.pop (); Q.push (a[i].x); now=now+a[i].x-h;}} cout<<ans<< Endl;}
Bzoj 1029: [JSOI2007] Construction Repair Priority queue