This page is still under construction.

Parts of this page are still being built. What you see may change.

Microbe Experiment (Bug Party)

Interview

Time limit2sMemory limit128 MB

Summary
Choose the largest subset of microbes so that the average foo released by the subset does not exceed any chosen microbe's tolerance.
Level

Medium6 of 10

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

Problem

Have you heard of Just Odd Inventions Inc. (JOI for short)? Its business is to make "just odd inventions." One of its projects is to trap many microbes alive in a single petri dish.

There are NN microbes under study, numbered 1,2,…,N1, 2, \dots, N. When a microbe is trapped in the dish, it instantly releases a harmful substance called foo (fatally odd object) into the dish. All foo released by the trapped microbes is absorbed equally by every microbe in the dish. Each microbe has a foo tolerance; if it absorbs more foo than its tolerance, it dies.

Microbe ii releases aia_i milligrams of foo and tolerates bib_i milligrams. That is, if microbes i1,i2,…,iki_1, i_2, \dots, i_k are trapped, each of them absorbs (ai1+ai2+⋯+aik)/k(a_{i_1} + a_{i_2} + \dots + a_{i_k}) / k milligrams of foo, and microbe ii dies if this absorbed amount is greater than its tolerance bib_i.

You must trap as many microbes alive as possible. However, the corpses of dead microbes harm the environment inside the dish, so no microbe in the dish may die from absorbing foo.

Given the number of microbes and each microbe's foo release amount and tolerance, find the maximum number of microbes that can be trapped alive in a single dish.

Input

  • The first line contains an integer NN, the number of microbes under study.
  • Each of the next NN lines, the ii-th of them, contains two positive integers aia_i and bib_i separated by a space, meaning microbe ii releases aia_i milligrams of foo and tolerates bib_i milligrams.

Output

Print, on a single line, the maximum number of microbes that can be trapped alive in one dish.

Constraints

  • 1≤N≤3000001 \le N \le 300000 — the number of microbes under study
  • 1≤ai≤1000001 \le a_i \le 100000 — foo released by microbe ii (milligrams)
  • 1≤bi≤1000001 \le b_i \le 100000 — foo tolerance of microbe ii (milligrams)

Note that the sum of released foo may exceed the range of a 32-bit integer, so use 64-bit integers.

Hint

In the sample input (6 microbes), if microbes 2, 4, and 5 are placed in the dish, the total foo released is 5+10+6=215 + 10 + 6 = 21 milligrams, so each microbe absorbs 21/3=721 / 3 = 7 milligrams. Their tolerances are 9,12,79, 12, 7 milligrams respectively, so none of them dies. Moreover, it is impossible to place 4 or more microbes without any of them dying.

Examples1

  1. Example 1

    Input
    6
    12 8
    5 9
    2 4
    10 12
    6 7
    13 9
    
    Expected output
    3