I have two lists. List L1
contains all positive integers, list L2
contains positive numbers (e.g. 0.01,0.1,0.5,3,5,10,100....)
.
Given a small positive number M
(e.g. 0.10948472)
, find a,b
from L1 and c
from L2
s.t. (b/a)*c
is maximized but still <=M
Note that list L2
is fixed (length around 7000
), list L1
has variable length (can have single element or up to 3000
elements).
How can we efficiently design an algorithm to solve this? I'm thinking about using divide and conquer on list L1
to break it into two then combine, but didn't work out. Anyone can solve it efficiently?
Update: Currently I worked out some inefficient but correct solutions: Sort 'L1' first. Divide 'L1' into two chunks: one chunk is the first N-1
elements, another chunk is the last element. Suppose best a,b,c
has been found on the first N-1
elements of L1
, I check whether we can find some a
in first chunk and b
in second chunk (one element only) and some c
, such that (b/a)*c
improves. Since I have to loop through each element in L2
, although it's nlogn, still appears to be slow