In Computer Science we hold weird ceremonies -- at each ceremony we display all our candles but
only n of them are lit (yeah, a binary code). Unfortunately we have 2
different types of candles: we have n1 candles that each burn at the rate r1,
and n2 candles that each burn at the rate r2. (The rates are in mm/hr.)
Before each ceremony we can choose which n of our candles
will be the ones that are lit during the ceremony -- we do this in an attempt to keep our
candles approximately the same length. Given n, n1, r1, n2, and r2 return the number of ceremonies
required for us to return our candles to uniform length. If we can never achieve uniform length,
return -1.
(You may assume that
our candles are arbitrarily long or that our ceremonies are arbitrarily short so
we won't completely burn up any candles.)
|