This is an excellent problem to solve as an LP-problem.

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.