题目链接:codeforces 725D . Contest Balloons

先按气球数从大到小排序求出初始名次,并把名次排在第一队前面的队放入优先队列,按w-t-1值从小到大优先,然后依次给气球给排名在前面的的队,给完后自己的气球数减少,继续跟之前排在第一队后面的队比较,考虑是否加入队列,每次记录最好的名次。

 #include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;
typedef long long ll;
const int N = ;
struct team{
ll t, w, wa;
team(ll t = , ll w = ):t(t),w(w) { wa = w - t + ; }
bool operator < (const team &r)const{
return r.wa < wa;
}
}a[N];
bool cmp(team x, team y){
return x.t > y.t;
}
priority_queue<team>q;
int main(){
int n, i, j;
ll ans, a1;
scanf("%d", &n);
for(i = ; i < n; ++i)
scanf("%lld%lld", &a[i].t, &a[i].w);
sort(a+, a+n, cmp);
for(i = ; i < n; ++i){
if(a[i].t > a[].t)
q.push(team(a[i].t, a[i].w));
else break;
}
a1 = ans = i;//初始名次
while(!q.empty()){
team tt = q.top(); q.pop();
a[].t -= tt.wa;
if(a[].t < ) break;
for(j = i; j < n; ++j){
if(a[j].t > a[].t){
q.push(team(a[j].t , a[j].w));}
else break;
}
a1 += j - i - ;
i = j;
ans = min(ans, a1);
}
printf("%lld\n", ans);
return ;
}

最新文章

  1. 【WPF】整个自定义按钮后台添加
  2. SQL SERVER全面优化-------索引有多重要?
  3. CodeForces 515C. Drazil and Factorial
  4. iOS开发——源代码管理——SVN
  5. web前端基础篇⑧
  6. this.Invoke
  7. OC基础(16)
  8. dojo 十一 jsonp
  9. (转)Const,Const函数,Const变量,函数后面的Const
  10. openssl windows编译 32位&amp;64位
  11. strlen 与 sizeof
  12. JVM组成
  13. docker 数据卷管理
  14. 刘志梅201771010115.《面向对象程序设计(java)》第十七周学习总结
  15. Linux之cp、rm、mv
  16. Python 基础数据类型之set
  17. QQ 互联认证 回调地址提示说要http :// 但是事实不用
  18. django-template-forloop
  19. 29.OGNL与ValueStack(VS)-总结OGNL[重点]
  20. c# -- Form1_Load()不被执行的三个解决方法

热门文章

  1. Salted hash password
  2. cookie的三种操作方法
  3. PHP读取XML文件数据
  4. Python实现抓取页面上链接
  5. C# 窗体(登录界面)
  6. HTML5中的时间类型,另外EL表达式的时间值来读取时间,并且还可以更改时间
  7. Hdu 1443 Joseph
  8. spring使用elasticsearch 5.x
  9. Android安装失败 Installation error code: -110
  10. RSA算法基础详解