Codeforces 725D

把所有的队伍分成两种,一种是气球数多于自己的(当前排名比自己高的),一种是气球数不大于自己的
首先求出初始排名,然后肯定是要每次把气球给当前排名高于自己队的队伍(助人飞升),显然可以用堆维护,每次选出(t-w+1)最小的队伍
然后自己队伍的气球会减少,刷新自己的排名刷新答案并且把气球数多于自己队伍的队伍放入堆中

#include<cstdio>
#include<algorithm>
#include<queue>
#define N 300005
#define LL long long
#define RG register
using namespace std;

inline LL read()
{
    LL a=0;int f=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9'){a=a*10+c-'0';c=getchar();}
    return a*f;
}

struct node
{
    LL t,w;
    bool operator < (const node &c) const {return t>c.t;}
}team[N];
LL n,t,w;
int ans,_d;
priority_queue<LL,vector<LL>,greater<LL> >heap;

int main()
{
    n=read()-1;
    int i;
    t=read(),w=read();
    for(i=1;i<=n;++i)
        team[i].t=read(),team[i].w=read();
    sort(team+1,team+n+1);
    i=1;
    while(i<=n&&team[i].t>t) heap.push(team[i].w-team[i].t+1),++i;
    ans=i;
    while(!heap.empty())
    {
        LL x=heap.top();heap.pop();
        if(x>t) break;
        t-=x;++_d;
        while(i<=n&&team[i].t>t) heap.push(team[i].w-team[i].t+1),++i;
        ans=min(ans,i-_d);
    }
    printf("%d\n",ans);
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值