Gym - 101806T: Touch The Sky(贪心)
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!
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
3
30 10
30 20
30 30
3
4
0 10
2 4
5 3
8 2
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(贪心)的更多相关文章
- Gym 101806T Touch The Sky
http://codeforces.com/gym/101806/problem/T 题目 In the year 2117, Professor Jaemin Yu developed a line ...
- codeforces gym #102082C Emergency Evacuation(贪心Orz)
题目链接: https://codeforces.com/gym/102082 题意: 在一个客车里面有$r$排座位,每排座位有$2s$个座位,中间一条走廊 有$p$个人在车内,求出所有人走出客车的最 ...
- Gym 101873K - You Are Fired - [贪心水题]
题目链接:http://codeforces.com/gym/101873/problem/K 题意: 现在给出 $n(1 \le n \le 1e4)$ 个员工,最多可以裁员 $k$ 人,名字为 $ ...
- Gym 100886J Sockets 二分答案 + 贪心
Description standard input/outputStatements Valera has only one electrical socket in his flat. He al ...
- Gym - 100283K K. Cubes Shuffling —— 贪心
题目链接:http://codeforces.com/gym/100283/problem/K 题解: 要使其相邻两项的差值之和最小,那么越靠中间,其数值越小. 那么剩下的问题就是如何放数字了.一开始 ...
- 2016"百度之星" - 初赛(Astar Round2A)1006 Gym Class(HDU5695)——贪心+拓扑排序
分析:首先,利用贪心可知,如果要所有人的分数和最高,需要把序号大的优先放在前面.其次,对于a的前面不能为b,那么只能a在b前面了,那么就建立一条从a到b的边,并且b的入度加1.然后就是拓扑排序了.要分 ...
- Gym 100507J Scarily interesting! (贪心)
Scarily interesting! 题目链接: http://acm.hust.edu.cn/vjudge/contest/126546#problem/D Description This y ...
- CodeForces - 1013C C - Photo of The Sky 贪心
题目链接: https://vjudge.net/problem/1735276/origin 题目大意与思路: 题目的基本意思就是求一个矩形的最小面积. 这个可以用最大最小值, 将他们分为X和Y组. ...
- scala 学习笔记(06) OOP(下)多重继承 及 AOP
一.多继承 上篇trait中,已经看到了其用法十分灵活,可以借此实现类似"多重继承"的效果,语法格式为: class/trait A extends B with C with D ...
随机推荐
- git报错fatal: I don't handle protocol 'https'处理
一.背景说明 今天使用在Cygwin中git clone时报fatal: I don't handle protocol 'https',如下: 以为是Cygwin实现的git有点问题没太在意,换去 ...
- 把旧系统迁移到.Net Core 2.0 日记(2) - 依赖注入/日志NLog
Net Core 大量使用依赖注入(Dependency Inject), 打个比方,我们常用的日志组件有Log4Net,NLog等等. 如果我们要随时替换日志组件,那么代码中就不能直接引用某个组件的 ...
- ie edge 自动给数字加下划线
<meta name="format-detection" content="telephone=no,email=no,address=no">
- 交互式shell编程
FQ #!/usr/bin/env shxfce4-terminal -x sudo python ./local/proxy.py 连续执行 gnome-terminal -x bash -c &q ...
- zabbix3.4.7集成grafana详细步骤
打开官方网站下载grafana并安装 wget https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana-5.0.4-1. ...
- react router @4 和 vue路由 详解(五)react怎么通过路由传参
完整版:https://www.cnblogs.com/yangyangxxb/p/10066650.html 7.react怎么通过路由传参? a.通配符传参(刷新页面数据不丢失) //在定义路由的 ...
- learning ddr tRP and tRP tRTP CL tRAS
referce :https://blog.csdn.net/ghostyu/article/details/7728106 tRP(RAS Precharge Time): “内存行地址控制器预充电 ...
- CF712E [Memort and Casinos]
题意 每次询问一段区间[l,r],求从最左边走到最右边(r+1)的概率(若走到l-1,则GG了),每个点上写有向右走的概率.支持单点修改. 思考 若只查询一次,那只要知道每个点在不走到l-1的情况下, ...
- 3.1 Makefile
安装make 安装make sudo apt-get install make make -v
- linux 系统监控、诊断工具之 lsof 用法简介
1.lsof 简介 lsof 是 Linux 下的一个非常实用的系统级的监控.诊断工具. 它的意思是 List Open Files,很容易你就记住了它是 "ls + of"的组合 ...