http://www.lydsy.com/JudgeOnline/problem.php?id=1029
Test instructions
Ideas:
Sort by T2 first, and maintain a T1 priority queue, and then for each building, if the current building can be repaired, then fix it. If it doesn't work, then it pops up from the priority queue for the longest time needed to repair the previous building, and if the time is longer than my current construction time and can fix the current building after removing it, then we'll give up that and repair the current building instead, because it will have a smaller total time.
1#include <iostream>2#include <algorithm>3#include <cstring>4#include <cstdio>5#include <sstream>6#include <vector>7#include <stack>8#include <queue>9#include <cmath>Ten#include <map> One#include <Set> A using namespacestd; -typedefLong Longll; -typedef pair<int,ll>PLL; the Const intINF =0x3f3f3f3f; - Const intmaxn=50000+5; - - intN; + - structnode + { A intCost,end; at}a[150005]; - - BOOLCMP (Node A, Node B) - { - returna.end<B.end; - } in - BOOL operator< (node& A, node&b) to { + returnA.cost>B.cost; - } the * intMain () $ {Panax Notoginseng //freopen ("In.txt", "R", stdin); - while(~SCANF ("%d",&N)) the { + for(intI=1; i<=n;i++) scanf ("%d%d",&a[i].cost,&a[i].end); ASort (A +1, A +1+n,cmp); thepriority_queue<int>Q; + - intt=0; $ intans=0; $ for(intI=1; i<=n;i++) - { - if(T+a[i].cost<=a[i].end) {ans++;t+=A[i].cost; Q.push (a[i].cost);} the Else - {Wuyi if(T-q.top () +a[i].cost<=a[i].end && q.top () >=a[i].cost) the { -T=t-q.top () +A[i].cost; Wu Q.pop (); - Q.push (a[i].cost); About } $ } - } -printf"%d\n", ans); - } A return 0; +}
Bzoj 1029: [JSOI2007] Construction repair (greed)