Hiring

Time limit1sMemory limit128 MB

Summary
Choose a real wage coefficient k and a subset of workers so that each hired worker's pay Q_i*k meets their minimum S_i and the total pay stays within budget W, maximizing the subset size.
Level

Hard8 of 10

Topics
Sorting, Greedy, Binary search, Math
Solved
No attempts yet

Problem

Jaehyun is hiring workers to build a skyscraper called the "Second Apple Tower". There are NN applicants numbered from 11 to NN. Worker ii has a minimum wage SiS_i and a construction-certificate level QiQ_i, so hiring worker ii requires paying them a wage of at least SiS_i.

To promote construction certificates, the government made a rule that every hired worker's wage must be directly proportional to their certificate level. That is, once a single real coefficient kk is chosen, each hired worker ii is paid exactly Qi×kQ_i \times k. Wages may be real numbers, not just integers. Because every hired worker must satisfy Qi×k≥SiQ_i \times k \ge S_i, the coefficient kk must be chosen large enough to meet the minimum-wage requirement of all hired workers.

Jaehyun has WW dollars. He does not care about certificate levels and only wants to finish the building as fast as possible, so he wants to hire as many workers as possible while keeping the total wage he pays at most WW. Find the maximum number of workers he can hire.

Input

The following data is given on standard input.

  • The first line contains the number of workers NN and the amount of money WW, separated by a space.
  • Each of the next NN lines contains the minimum wage SiS_i and the certificate level QiQ_i of worker ii, separated by a space (the ii-th such line describes worker ii).

Output

Print a single integer: the maximum number of workers that can be hired within the budget.

Constraints

  • 1≤N≤500,0001 \le N \le 500{,}000 (number of applicants)
  • 1≤Si≤20,0001 \le S_i \le 20{,}000 (minimum wage of worker ii)
  • 1≤Qi≤20,0001 \le Q_i \le 20{,}000 (certificate level of worker ii)
  • 1≤W≤10,000,000,0001 \le W \le 10{,}000{,}000{,}000 (amount of money available)
  • All numbers given in the input are integers.

Examples3

  1. Example 1

    Input
    4 100
    5 1000
    10 100
    8 10
    20 1
    
    Expected output
    2
    
  2. Example 2

    Input
    3 4
    1 2
    1 3
    1 3
    
    Expected output
    3
    
  3. Example 3

    Input
    3 40
    10 1
    10 2
    10 3
    
    Expected output
    2