CF725D.Contest Balloons
普及+/提高
通过率:0%
时间限制:3.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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 t__i balloons and weight w__i. It's guaranteed that t__i doesn't exceed w__i 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?
ACM-ICPC 竞赛的一项传统是:每解出一道题,一支队伍就会获得一个气球。我们假设提交时间无关紧要,队伍仅按所拥有的气球数量进行排名。这意味着某支队伍的名次等于气球数量严格多于它的队伍数加 1。例如,若有七支队伍的气球数量比你多,则你的名次为第八名。允许并列。
你应该知道,赛前进食非常重要。若一支队伍的气球数量大于该队的重量,则这支队伍会连同其工作台一起升空飘浮。最终他们将触碰到天花板,而这是竞赛规则严格禁止的。此时该队将被取消资格,并不参与最终排名。
一场比赛刚刚结束。共有 n 支队伍,编号为 1 至 n。第 i 支队伍拥有 ti 个气球,重量为 wi。题目保证初始时对所有 i 都有 ti≤wi,因此没有任何队伍一开始就会飘浮。
Limak 是第一支队伍的成员。他不喜欢作弊,绝不会从其他队伍窃取气球。相反,他可以将自己的气球赠送给其他队伍(这可能导致那些队伍飘浮)。Limak 可以赠送零个或多个气球,但显然不能赠送超过本队初始所拥有的气球数量。
Limak 能够获得的最好名次是多少?
输入格式
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 t__i and w__i (0 ≤ t__i ≤ w__i ≤ 1018) — respectively the number of balloons and the weight of the i-th team. Limak is a member of the first team.
标准输入的第一行包含一个整数 n(2 ≤ n ≤ 300000)—— 表示队伍的数量。
接下来的 n 行中,第 i 行包含两个整数 ti 和 wi(0 ≤ ti ≤ wi ≤ 1018)—— 分别表示第 i 支队伍的气球数量和重量。Limak 属于第一支队伍。
输出格式
Print one integer denoting the best place Limak can get.
输出一个整数,表示 Limak 能获得的最佳名次。
输入输出样例
输入#1
8 20 1000 32 37 40 1000 45 50 16 16 16 16 14 1000 2 1000
输出#1
3
输入#2
7 4 4 4 4 4 4 4 4 4 4 4 4 5 5
输出#2
2
输入#3
7 14000000003 1000000000000000000 81000000000 88000000000 5000000000 7000000000 15000000000 39000000000 46000000000 51000000000 0 1000000000 0 0
输出#3
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).
在第一个样例中,Limak 最初有 20 个气球。共有三支队伍的气球数更多(分别为 32、40 和 45 个气球),因此 Limak 最初排名第四。一种最优策略如下:
- Limak 向一支拥有 32 个气球、重量为 37 的队伍赠送 6 个气球,这恰好使其升空。不幸的是,Limak 此时仅剩 14 个气球,将跌至第五名。
- Limak 向一支拥有 45 个气球的队伍赠送 6 个气球。该队气球数变为 51,重量为 50,因此升空并被取消资格。
- Limak 分别向两支最初拥有 16 个气球的队伍各赠送 1 个气球。
- Limak 剩余气球数为 20 − 6 − 6 − 1 − 1 = 6 个。
- 其余还有三支队伍,其气球数分别为 40、14 和 2。
- Limak 获得第三名,因为有两支队伍的气球数比他多。
在第二个样例中,Limak 排名第二,且无法提升名次。
在第三个样例中,Limak 恰好有足够的气球来淘汰第 2、第 3 和第 5 支队伍(其气球数分别为 81000000000、5000000000 和 46000000000)。在耗尽全部气球后,他将与第 6 队和第 7 队并列第二名。
输入解题思路,AI测评打分。不知道怎么写?