Tour de France
Time limit1sMemory limit128 MB
Given front and rear sprocket tooth counts, find the maximum ratio between adjacent attainable drive ratios n/m across all pairs.
- Level
Medium5 of 10
- Topics
- Sorting, Math, Brute force, Number theory
- Solved
- No attempts yet
Problem
A racing bicycle is driven by a chain that connects two sprockets. The sprockets form two clusters: a front cluster (usually 2 or 3 sprockets) and a rear cluster (usually 5 to 10 sprockets). At any moment the chain links exactly one front sprocket to one rear sprocket.
The drive ratio -- the ratio of the angular velocity of the pedals to that of the wheels -- equals , where is the number of teeth on the chosen rear sprocket and is the number of teeth on the chosen front sprocket.
Two drive ratios are adjacent when no other attainable drive ratio satisfies . The spread of a pair is their quotient .
For a given pair of front and rear clusters, compute the maximum spread over all adjacent pairs of attainable drive ratios.
Input
The input contains several test cases and ends with a line containing a single .
Each test case consists of:
- : the number of sprockets in the front cluster;
- : the number of sprockets in the rear cluster;
- integers giving the teeth counts of the front sprockets;
- integers giving the teeth counts of the rear sprockets.
No cluster has more than sprockets, and every sprocket has at least and at most teeth.
Output
For each test case, print the maximum spread rounded to two decimal places (rounding halves up), one value per line.