CF725D.Contest Balloons

普及/提高-

通过率:0%

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 11 . 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 nn teams, numbered 11 through nn . The ii -th team has tit_{i} balloons and weight wiw_{i} . It's guaranteed that tit_{i} doesn't exceed wiw_{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?

输入格式

The first line of the standard input contains one integer nn ( 2<=n<=3000002<=n<=300000 ) — the number of teams.

The ii -th of nn following lines contains two integers tit_{i} and wiw_{i} ( 0<=ti<=wi<=10180<=t_{i}<=w_{i}<=10^{18} ) — respectively the number of balloons and the weight of the ii -th team. Limak is a member of the first team.

输出格式

Print one integer denoting the best place Limak can get.

输入输出样例

  • 输入#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 2020 balloons initially. There are three teams with more balloons ( 3232 , 4040 and 4545 balloons), so Limak has the fourth place initially. One optimal strategy is:

  1. Limak gives 66 balloons away to a team with 3232 balloons and weight 3737 , which is just enough to make them fly. Unfortunately, Limak has only 1414 balloons now and he would get the fifth place.
  2. Limak gives 66 balloons away to a team with 4545 balloons. Now they have 5151 balloons and weight 5050 so they fly and get disqualified.
  3. Limak gives 11 balloon to each of two teams with 1616 balloons initially.
  4. Limak has 206611=620-6-6-1-1=6 balloons.
  5. There are three other teams left and their numbers of balloons are 4040 , 1414 and 22 .
  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 22 , 33 and 55 (the teams with 8100000000081000000000 , 50000000005000000000 and 4600000000046000000000 balloons respectively). With zero balloons left, he will get the second place (ex-aequo with team 66 and team 77 ).

首页