Suppose we have $r$ copies of the integer $a$ and $t$ copies of the integer $b$, and a capacity $C$. We would like to find the maximum sum of the given integers, that is at most $C$.
This is a special case of the subset sum problem. Since there are at most $(r+1)(t+1)$ possible sums, one can just check all of them and find the maximum sum that is at most $C$. But this takes time $O(r t)$, while the size of the input - if it is given in binary - is $\log{(r t a b)}$.
Is there an algorithm that solves the problem in time polynomial in the size of the binary representation of the input?