There are $n$ sources with the following positive volumes: $p_1, ..., p_n$ and there are $m$ destinations with the following positive volumes: $q_1, ..., q_m$. It is known that $p_1+ ...+ p_n=q_1+ ...+ q_m$. Each source is going to use its volume to fill up one or more destination(s). If a source fills one destination, we are paying $1$ for it. If it fills $k$ destinations we are paying $k$ for it. The problem is to fill destinations using the sources so that the price is the smallest possible.
I need a help coming up with the algorithm for the problem.
Frankly speaking I am very lost here and can not come up with the algorithm which would be at least constantly better than going over all the possible fillings and choosing the one with the smallest price.
The thing I pondered over was sorting the sources in the ascending order and then taking the sources one by one, but I can not prove the correctness of such an approach.