BZOJ1029 [JSOI2007]建筑抢修

一开始以为是个线段覆盖,后来仔细一读才发现有固定的结束时间。

类似于线段覆盖按右端点排序,使劲往里加然后加不了就用现在的换,使得所用时间尽量短。

PS:VANE最近回家养老了,只有大奕哥来撑场子了。

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 typedef long long ll;
 4 priority_queue<ll>q;
 5 struct node{
 6     ll a,b;
 7     bool operator <(const node &c)const{
 8         return b==c.b?a<c.a:b<c.b;
 9     }
10 }t[150005];
11 int main()
12 {
13     int n;
14     scanf("%d",&n);ll now=0;ll ans=0;
15     for(int i=1;i<=n;++i)
16     {
17         scanf("%lld%lld",&t[i].a,&t[i].b);
18     }
19     sort(t+1,t+1+n);
20     for(int i=1;i<=n;++i)
21     {
22         if(now+t[i].a<=t[i].b)now+=t[i].a,ans++,q.push(t[i].a);
23         else if(t[i].a<q.top())
24         {
25             now-=q.top();q.pop();q.push(t[i].a);now+=t[i].a;
26         }
27     }
28     printf("%lld\n",ans);
29     return 0;
30 }

 

posted @ 2018-01-21 19:46  大奕哥&VANE  阅读(124)  评论(0编辑  收藏  举报