1/22 测试一(STL 模拟 贪心)

C.(贪心,给出气球,输出最好成绩)Contest Balloons

One tradition of ACM-ICPC contests is that a team gets a balloon for every solved problem. We assume that the submission time doesn’t matter and teams are sorted only by the number of balloons they have. It means that one’s place is equal to the number of teams with more balloons, increased by 1. For example, if there are seven teams with more balloons, you get the eight place. Ties are allowed.
You should know that it’s important to eat before a contest. If the number of balloons of a team is greater than the weight of this team, the team starts to float in the air together with their workstation. They eventually touch the ceiling, what is strictly forbidden by the rules. The team is then disqualified and isn’t considered in the standings.
A contest has just finished. There are n teams, numbered 1 through n. The i-th team has ti balloons and weight wi. It’s guaranteed that ti doesn’t exceed wi so nobody floats initially.
Limak is a member of the first team. He doesn’t like cheating and he would never steal balloons from other teams. Instead, he can give his balloons away to other teams, possibly making them float. Limak can give away zero or more balloons of his team. Obviously, he can’t give away more balloons than his team initially has.
What is the best place Limak can get?
Input
The first line of the standard input contains one integer n (2 ≤ n ≤ 300 000) — the number of teams.
The i-th of n following lines contains two integers ti and wi (0 ≤ ti ≤ wi ≤ 1018) — respectively the number of balloons and the weight of the i-th team. Limak is a member of the first team.
Output
Print one integer denoting the best place Limak can get.
Example
Input
8
20 1000
32 37
40 1000
45 50
16 16
16 16
14 1000
2 1000
Output
3
Input
7
4 4
4 4
4 4
4 4
4 4
4 4
5 5
Output
2
Input
7
14000000003 1000000000000000000
81000000000 88000000000
5000000000 7000000000
15000000000 39000000000
46000000000 51000000000
0 1000000000
0 0
Output
2
Note
In the first sample, Limak has 20 balloons initially. There are three teams with more balloons (32, 40 and 45 balloons), so Limak has the fourth place initially. One optimal strategy is:
1、Limak gives 6 balloons away to a team with 32 balloons and weight 37, which is just enough to make them fly. Unfortunately, Limak has only 14 balloons now and he would get the fifth place.
2、Limak gives 6 balloons away to a team with 45 balloons. Now they have 51 balloons and weight 50 so they fly and get disqualified.
3、Limak gives 1 balloon to each of two teams with 16 balloons initially.
4、Limak has 20 - 6 - 6 - 1 - 1 = 6 balloons.
5、There are three other teams left and their numbers of balloons are 40, 14 and 2.
6、Limak gets the third place because there are two teams with more balloons.
In the second sample, Limak has the second place and he can’t improve it.
In the third sample, Limak has just enough balloons to get rid of teams 2, 3 and 5 (the teams with 81 000 000 000, 5 000 000 000 and 46 000 000 000 balloons respectively). With zero balloons left, he will get the second place (ex-aequo with team 6 and team 7).

题意:
共有n个队伍,你是第一队的成员,每个队有t个气球,队伍的重量是w,若w > t ,则队伍会飞起来,失去比赛资格。你可以将气球给别的队伍,使他们飞起来,但是你不接受别的队伍的气球。要求输出你可以得到的最好名次。

思路:
将排在你前面的队伍单独拿出来,将他们距离飞起来需要的气球从小到大排序。每次取出飞起代价最小的那个,如果你能够让他飞起来,那么就让他飞起来,将他踢出队伍,同时要注意更新新的排序,将排在你前面的队伍放到前面的序列中,重复操作。在这个过程中不断更新取得的名次,最终取过程中获得的最小名次即可。

#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <vector>
#include <map>
#include <queue>
#define MAXN 300005
#define INF 0x3f3f3f3f3f3f3f3f
typedef long long ll;
using namespace std;int main()
{int n;scanf("%d", &n);ll me = 0, t, w;int ans, cur = 1;priority_queue<ll, vector<ll>, greater<ll> > big;multimap<ll, ll, greater<ll> > sma;for(int i = 0; i < n; i++){scanf("%lld%lld", &t, &w);if(i == 0)me = t;else if(t > me){big.push(w - t + 1);
//                ll p = big.top();
//                cout<<'@'<<p<<endl;cur++;}else if(t <= me)sma.insert(pair<ll, ll>(t, w));}ans = cur;
//    cout<<"ans: "<<ans<<endl;
//    ll p = big.top();
//        cout<<'*'<<p<<endl;while(!big.empty() && big.top() <= me){
//        ll p = big.top();
//        cout<<'*'<<p<<endl;me -= big.top();
//        cout<<"me: "<<me<<endl;big.pop();cur--;multimap<ll, ll, greater<ll>> ::iterator iter = sma.begin();
//        p = iter->first;
//            cout<<'#'<<p<<endl;while(!sma.empty() && iter->first > me){cur++;
//            p = iter->first;
//            cout<<'#'<<p<<endl;big.push(iter->second - iter->first + 1);
//            cout<<"charu"<<iter->second - iter->first + 1<<endl;sma.erase(iter);iter = sma.begin();}ans = min(ans, cur);
//        cout<<"cur: "<<cur<<endl;
//        cout<<"ans: "<<ans<<endl;}printf("%d\n", ans);return 0;
}

1/22 测试一(STL 模拟 贪心)C.(贪心,给出气球,输出最好成绩)Contest Balloons相关推荐

  1. C++ STL : 模拟实现STL中的关联式容器unordered_map/unordered_set

    目录 unordered_map/unordered_set unordered_map/unordered_set与map/set的区别 底层哈希桶的改造 仿函数 Key值的获取方法 hash(ke ...

  2. 存根类 测试代码 java_测试双打:模拟,假人和存根

    存根类 测试代码 java 大多数班级都有合作者. 在进行单元测试时,您通常希望避免使用那些协作者的实际实现方式来避免测试的脆弱性和绑定/耦合,而应使用测试双打:模拟,存根和双打. 本文引用了有关该主 ...

  3. 测试双打:模拟,假人和存根

    大多数班级都有合作者. 在进行单元测试时,您通常希望避免使用那些协作者的实际实现方式来避免测试的脆弱性和绑定/耦合,而应使用测试双打:模拟,存根和双打. 本文引用了有关该主题的两篇现有文章:Marti ...

  4. 手机模拟续航测试软件,3D模拟+1080p视频 中兴星星1号续航测试

    在韩剧<来自星星的你>大热的时候,一颗来自国产的"星星"于韩国横空出世.中兴星星1号这款一经面世便号称最美的手机经过了我们一轮又一轮的测试,也向我们证明了它不仅拥有精致 ...

  5. Java储蓄账户类及测试类,模拟存款

    老师布置了一个实验题:编写储蓄账户类及测试类,模拟存款,参考以下运行方式: 1.新开5个储蓄账户,各储蓄账户的编号.户名在新开储蓄账户时初始化,假设每位用户新开储蓄账户时都存入了一笔钱. 2.提示用户 ...

  6. C++的STL 栈实现 判断栈的出栈顺序是否合理

    有这样的题目: 已知从1至n的数字序列,按顺序入栈,每个数字入栈后即可出栈, 也可在栈中停留,等待后面的数字入栈出栈后,该数字再出栈,求该数字序列的出栈序列是否合法? 类似如下: 已知栈的出栈序列为: ...

  7. Java开发中巧妙使用链表来实现模拟栈的入栈出栈操作

    2019独角兽企业重金招聘Python工程师标准>>> 在Java开发中经常会碰到需要你用Java链表来实现入栈出栈的模拟操作,下文就这个操作做了一个详细的描述. 栈:后进先出:最后 ...

  8. java sleep 抛出异常_PowerMockito模拟Thread.sleep()时抛出中断异常的场景

    点击蓝色字免费订阅,每天收到这样的好信息 前言:最近有不少粉丝关注本公众号.并且我已经成功开通了流量主同时会赚一点点广告费,我打算每个月把这部分钱拿出来给大家买点书刊,算是给大家一点福利吧.大家想买什 ...

  9. 如何测试支付宝手机充值的这个功能,写出测试用例

    有人在面试软件测试的时候,被问到如何测试支付宝手机充值的这个功能,写出测试用例. 其实无论测试什么,我们首先的需要梳理软件业务的流程,来看看支付宝充值都有哪些流程? 首先,面试官如果给出的是这样一个场 ...

最新文章

  1. IntelliJ IDEA 最常用配置,应用、永久激活
  2. mips汇编计算开方_清华考研辅导班-2020清华大学912计算机专业基础综合考研经验真题参考书目...
  3. linux ping监控脚本,WINDOWS和LINUX下带时间的PING包监控脚本
  4. android BluetoothAdapter蓝牙BLE扫描总结
  5. python:找出两个列表中相同和不同的元素(使用推导式)
  6. VC 2008 Express 编译OpenCV2.0/2.1
  7. java高级教程pdf_《Java高级编程实用教程》PDF 下载_IT教程网
  8. 洛谷4578 LOJ2520:[FJOI2018]所罗门王的宝藏——题解
  9. 航班时间(计算时间差)
  10. excel单元格数据有效性自定义
  11. 解析ESX SERVER故障数据恢复方法
  12. Java中的代理(静态代理和动态代理)
  13. 第三方登录数据库用户表结构设计
  14. 吸烟行为检测系统(Python+YOLOv5深度学习模型+清新界面)
  15. 南京大学软件学院 西交计算机,2021届薪酬最高的十大本科专业,前三名都是计算机和相关专业...
  16. idea设置了默认换行符,ctl + s 保存文件时换行符没有变成默认换行符 解决方法
  17. webpack webpack-cli
  18. 41岁了,我该何去何从?
  19. 【C语言练习题】斐波那契
  20. 2023年PMP考试内容有哪些?怎么备考?

热门文章

  1. 2023年【煤气】考试报名及煤气证考试
  2. collect2.exe: error: ld returned 1 exit status
  3. 码蹄集 tourist
  4. ITextSharp 批量电子签章
  5. BIND DNS配置详解
  6. Linux搭建部落冲突,Neovim+Coc.nvim配置 目前个人最舒服终端编辑环境(PythonC++)
  7. python argmin_Python numpy.argmin函数方法的使用
  8. 最大同性交友网站Github(一)——介绍与使用
  9. SQL --- 数据的筛选与排序
  10. 如何确定当前的S7-1200PLC使用的具体的博途软件和固件版本?