Because of the specific terminology in use, I cannot understand the details. More specifically, I have no idea what a Downline is nor what AllLegs can mean.
Anyway, it seems to me that this problem can be formulated as a set of linear inequations of the form 0 <= x <= M, x + y + z <= N, or similar, and you need to either find an admissible solution or maximize some criterion.
You will need to resort to the techniques of linear programming (
http://en.wikipedia.org/wiki/Linear_programming[
^]). The set of admissible solutions corresponds to a polyedron in space (actually a 6-polytope in 6-hyperspace), and possibly use the Simplex algorithm (
http://en.wikipedia.org/wiki/Simplex_algorithm[
^]).
This may look scary at first glance, but is manageable. You first step in this search is to establish the inequations between all your parameters.
Last minute: good news for you, Excel has an add-in module called the Solver that is able to handle such linear programming problems (
http://office.microsoft.com/en-us/excel-help/about-solver-HP005198368.aspx?CTT=3[
^]).