Assuming that the entries of B positive (it seems that this special case may be useful to you), there exists an O(n^2 log n) algorithm.
Let first solve the problem of solving for a specific t whether there exists a solution such that
(sum a[i(j)])/(sum b[i(j)]) >= t.
Cleaning the denominator, this condition is equivalent
sum (a[i(j)] - t*b[i(j)]) >= 0.
All we need to do is select the k largest values a[i(j)] - t*b[i(j)] .
Now, to solve the problem when t unknown, we use the kinetic algorithm. Think t is a temporary variable; we are interested in the evolution of a one-dimensional physical system with n particles having initial positions A and velocities -B . Each particle crosses each other particle no more than once, therefore the number of events is O(n^2) . Between the intersections, the optimal sum (a[i(j)] - t*b[i(j)]) varies linearly, since the same subset k is optimal.
source share