D
来源:互联网 发布:网络盒子破解软件 编辑:程序博客网 时间:2024/05/10 02:20
D - Codeforc
es 725D
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?
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.
Print one integer denoting the best place Limak can get.
820 100032 3740 100045 5016 1616 1614 10002 1000
3
74 44 44 44 44 44 45 5
2
714000000003 100000000000000000081000000000 880000000005000000000 700000000015000000000 3900000000046000000000 510000000000 10000000000 0
2
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:
- 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.
- 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.
- Limak gives 1 balloon to each of two teams with 16 balloons initially.
- Limak has 20 - 6 - 6 - 1 - 1 = 6 balloons.
- There are three other teams left and their numbers of balloons are 40, 14 and 2.
- 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).
- d
- d
- d
- d
- d
- D
- d
- d
- d
- d
- d
- %d
- d
- d
- d
- D
- d
- d
- 不同系统换行符的定义 加read(),readline(),readlines()的使用及注意事项
- 优先队列优化的求最短路和次短路条数以及长度的模板
- EM(期望最大化)算法(1):初探原理
- mysql_分组
- opencv3图像灰度化处理 c++
- D
- Windows7下安装与破解IntelliJ IDEA2017
- 贪心算法
- Java设计模式-享元模式
- 源码网站的记录
- python中pandas包中的DataFrame有关操作iloc与.loc的区别
- php 当前日期加一天和指定日期加一天
- HDU 3874 离线处理,树状数组
- mac下tomcat不正常关闭导致端口占用