Figure: The house floats up in the sky by balloons. This picture is also used in 2018 KAIST RUN Spring Contest poster.

In the year 2117, Professor Jaemin Yu developed a linear-time algorithm for TSP(Traveling Salesperson Problem). Not long after that happened, all computer systems were destroyed, and nuclear weapons demolished all the lands. You, a great computer expert, also lost your job. With a great despair, you lost your meaning of life long ago. All those things that made your heart beat – where had they gone? After questioning yourself again and again, your conclusion is ...

"If I go to KAIST where I started my first ICPC, can I find a meaning of my life?"

All transportations were destroyed, but you were an avid ICPC participant, and you collected a lot of century-old balloons in Korean Regionals. If you could float a house with some of those balloons...

Currently you have N balloons, and you are trying to float the house into the sky by attaching balloons on the rooftop. Every balloon have altitude limit Li and capacity Di, which indicates you can blow balloons in altitude at most Li, and the balloon busts after increasing the altitude by Di.

Your journey starts at altitude 0. If you have more than 1 balloons enlarged, then the house will ascend too fast. Thus, you will blow one balloon and attach it at the rooftop, increase the altitude until the balloons bust, blow the other balloon and attach it to increase the altitude... to make your house float. For convenience, you may assume that balloons can only increase the altitude.

You don't care about your final altitude, but a balloon can move a fixed amount of distance. Thus, you want to bust as many balloons as possible. You want to calculate a maximum number of balloons you can bust, and check if you can make a journey to KAIST. Let's see whether your 100-year-old ICPC experience can help on this problem!

Input

The first line contains N, the number of balloons. (1 ≤ N ≤ 250, 000)

In next N lines, the altitude limit of i-th balloon Li, and capacity of i-th balloon Di are given as two space-separated integers. (0 ≤ Li ≤ 1015, 1 ≤ Di ≤ 109)

Output

Print the maximum number of balloons you can bust.

Examples

Input
3
30 10
30 20
30 30
Output
3
Input
4
0 10
2 4
5 3
8 2
Output
3

题意:现在有N个气球,第i个气球可以使用的条件是高度不大于Li,使用后高度会增加Di,问最多用多少个气球。

思路:这类题肯定是要先排序,然后贪心或者DP。 反正就是按Li和Di排序后都不好操作。 我们按照Li+Di排序,然后用一个大根堆,里面保存的是增加的高度。

如果当前高度大于Li,但是Di比较小,我们用它的Di去换大根堆里最大的一个。 这样是完全无后效性的。

#include<bits/stdc++.h>
#define ll long long
#define rep(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
priority_queue<int>q;
struct in{
ll x,y;
bool friend operator<(in w,in v){ return w.x<v.x; }
}s[];
int main()
{
int N; ll Now=; scanf("%d",&N);
rep(i,,N) {
scanf("%lld%lld",&s[i].x,&s[i].y);
s[i].x+=s[i].y;
}
sort(s+,s+N+);
rep(i,,N){
Now+=s[i].y; q.push(s[i].y);
if(Now>s[i].x){
Now-=q.top();
q.pop();
}
}
printf("%d\n",q.size());
return ;
}

Gym - 101806T: Touch The Sky(贪心)的更多相关文章

  1. Gym 101806T Touch The Sky

    http://codeforces.com/gym/101806/problem/T 题目 In the year 2117, Professor Jaemin Yu developed a line ...

  2. codeforces gym #102082C Emergency Evacuation(贪心Orz)

    题目链接: https://codeforces.com/gym/102082 题意: 在一个客车里面有$r$排座位,每排座位有$2s$个座位,中间一条走廊 有$p$个人在车内,求出所有人走出客车的最 ...

  3. Gym 101873K - You Are Fired - [贪心水题]

    题目链接:http://codeforces.com/gym/101873/problem/K 题意: 现在给出 $n(1 \le n \le 1e4)$ 个员工,最多可以裁员 $k$ 人,名字为 $ ...

  4. Gym 100886J Sockets 二分答案 + 贪心

    Description standard input/outputStatements Valera has only one electrical socket in his flat. He al ...

  5. Gym - 100283K K. Cubes Shuffling —— 贪心

    题目链接:http://codeforces.com/gym/100283/problem/K 题解: 要使其相邻两项的差值之和最小,那么越靠中间,其数值越小. 那么剩下的问题就是如何放数字了.一开始 ...

  6. 2016"百度之星" - 初赛(Astar Round2A)1006 Gym Class(HDU5695)——贪心+拓扑排序

    分析:首先,利用贪心可知,如果要所有人的分数和最高,需要把序号大的优先放在前面.其次,对于a的前面不能为b,那么只能a在b前面了,那么就建立一条从a到b的边,并且b的入度加1.然后就是拓扑排序了.要分 ...

  7. Gym 100507J Scarily interesting! (贪心)

    Scarily interesting! 题目链接: http://acm.hust.edu.cn/vjudge/contest/126546#problem/D Description This y ...

  8. CodeForces - 1013C C - Photo of The Sky 贪心

    题目链接: https://vjudge.net/problem/1735276/origin 题目大意与思路: 题目的基本意思就是求一个矩形的最小面积. 这个可以用最大最小值, 将他们分为X和Y组. ...

  9. scala 学习笔记(06) OOP(下)多重继承 及 AOP

    一.多继承 上篇trait中,已经看到了其用法十分灵活,可以借此实现类似"多重继承"的效果,语法格式为: class/trait A extends B with C with D ...

随机推荐

  1. facebook视频上传python 返回错误code:100,'type':OAuthException

    首先重新获取访问口令token: https://developers.facebook.com/tools/debug/accesstoken/?q=EAAYDuzyd3eYBAK9lZCErZBl ...

  2. AI工具(缩放工具)(路径查找器)(旋转工具)(镜像工具)5.12

    缩放工具:选择图形,点击工具栏缩放工具,”ENTER"输入缩放比例,“复制”完成缩放复制. 路径查找器:选择两个图形,“窗口”“路径查找器”“差集”:大圆减去小圆,留下圆环. “减去顶层”: ...

  3. 线性回归之决定系数(coefficient of determination)

    1. Sum Of Squares Due To Error 对于第i个观察点, 真实数据的Yi与估算出来的Yi-head的之间的差称为第i个residual, SSE 就是所有观察点的residua ...

  4. ASP.Net MVC(1) 之走进MVC

    一.MVC三层架构: mvc三层架构,大家都比较熟悉了,这里再介绍一下.Mvc将应用程序分离为三个部分: Model:是一组类,用来描述被处理的数据,同时也定义这些数据如何被变更和操作的业务规则.与数 ...

  5. break&&continue

    break和continue的区别: 1. 当它们用在循环语句的循环体时,break用于立即退出本层循环,而continue仅仅结束本次循环(本次循环体内不执行continue语句后的其它语句,但下一 ...

  6. vue数据请求显示loading图

    一般项目中,有时候会要求,你在数据请求的时候显示一张gif图片,然后数据加载完后,消失.这个,一般只需要在封装的axios中写入js事件即可.当然,我们首先需要在app.vue中,加入此图片.如下: ...

  7. MySQL字符集与校对

    一.什么是字符集与校对 1.字符集与校对 字符集是指一种从二进制编码到某种字符符号的映射. 校队是指一组用于某个字符集的配许规则. 2.utf8与utf8mb4 标准的UTF-8字符集编码是可以使用1 ...

  8. python -input用户输入

    #接收用户输入信息用input就可以了 #还有输入密码的,也就是隐藏的,pycharm中不好用,要到命令行去 import getpass name = input('name:') age = in ...

  9. asp.net MVC之Action过滤器浅析

    在asp.net MVC中,Action过滤器是一大利器,它可以在以下两个步骤执行相关的代码: 1.执行Action方法之前:OnActionExecuting 2.Action方法执行完毕后:OnA ...

  10. MeshLab 编译

    1.需要以下:  MeshLab 1.3.3  下载地址 http://sourceforge.net/projects/meshlab/files/meshlab Win7 X64  Visual ...