Microbe Experiment (Bug Party)
InterviewTime limit2sMemory limit128 MB
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 microbes under study, numbered . 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 releases milligrams of foo and tolerates milligrams. That is, if microbes are trapped, each of them absorbs milligrams of foo, and microbe dies if this absorbed amount is greater than its tolerance .
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 , the number of microbes under study.
- Each of the next lines, the -th of them, contains two positive integers and separated by a space, meaning microbe releases milligrams of foo and tolerates milligrams.
Output
Print, on a single line, the maximum number of microbes that can be trapped alive in one dish.
Constraints
- — the number of microbes under study
- — foo released by microbe (milligrams)
- — foo tolerance of microbe (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 milligrams, so each microbe absorbs milligrams. Their tolerances are milligrams respectively, so none of them dies. Moreover, it is impossible to place 4 or more microbes without any of them dying.