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 }

 

转载于:https://www.cnblogs.com/nbwzyzngyl/p/8325185.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值