TITLE: Optimization algorithm sought
QUESTION [5 upvotes]: Suppose I have $N$ pairs of positive numbers $(a_1, b_1), (a_2, b_2), \dotsc, (a_N, b_N).$ and I want to find a subset of $M$ of them maximizing
$$
\frac{\sum_{j=1}^M a_{i_j}}{\sum_{j=1}^M b_{i_j}}.
$$
Can this be done in polynomial time?

REPLY [2 votes]: The paper "Dropping Lowest Grades" by Daniel M. Kane and Jonathan M. Kane addresses this question in the context of dropping $r$ quiz grades from a collection of weighted grades.
The solution described there is fundamental the same as that in David Eppstein's answer.  However, there is also a discussion of a practical implementation that may be even faster in practice.