Tour de France

Time limit1sMemory limit128 MB

Summary
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 n:mn:m, where nn is the number of teeth on the chosen rear sprocket and mm is the number of teeth on the chosen front sprocket.

Two drive ratios d1<d2d_1 < d_2 are adjacent when no other attainable drive ratio d3d_3 satisfies d1<d3<d2d_1 < d_3 < d_2. The spread of a pair d1<d2d_1 < d_2 is their quotient d2/d1d_2 / d_1.

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 00.

Each test case consists of:

  • ff: the number of sprockets in the front cluster;
  • rr: the number of sprockets in the rear cluster;
  • ff integers giving the teeth counts of the front sprockets;
  • rr integers giving the teeth counts of the rear sprockets.

No cluster has more than 1010 sprockets, and every sprocket has at least 1010 and at most 100100 teeth.

Output

For each test case, print the maximum spread rounded to two decimal places (rounding halves up), one value per line.

Examples2

  1. Example 1

    Input
    2 4
    40 50
    12 14 16 19
    0
    
    Expected output
    1.19
    
  2. Example 2

    Input
    1 2
    10
    10 100
    0
    
    Expected output
    10.00