Is Bigger Smarter?
Time limit1sMemory limit128 MB
Given pairs of weight and IQ for up to 1000 elephants, find the largest subset whose weights strictly increase while IQs strictly decrease.
- Level
Medium4 of 10
- Topics
- Dynamic programming, Sorting
- Solved
- No attempts yet
Problem
Some people think that the bigger an elephant is, the smarter it is. To disprove this, you want to take the data on a collection of elephants and select as large a subset as possible that can be arranged in a sequence so that the weights are strictly increasing while the IQs are strictly decreasing.
Input
The input consists of data for several elephants, one elephant per line, terminated by the end-of-file. The data for a particular elephant is a pair of integers: the first is its weight in kilograms and the second is its IQ in hundredths of an IQ point. Both integers are between 1 and 10000. The data contains information for at most 1000 elephants. Two elephants may have the same weight, the same IQ, or even the same weight and IQ.
Output
Let the weight and IQ of the -th elephant be and . Consider choosing a subset of elephants that can be ordered as so that
and
All inequalities are strict: the weights must be strictly increasing and the IQs must be strictly decreasing. Output a single line containing the maximum possible number of elephants in such a subset.