Let $n$ be the longest term (in months) of any of the loans.
Let $D_1,D_2,...,D_n$ be the amount due in month $n$. (Some of these values may be $0$.)
Let $C_k$ be the total cumulative amount due of all loans through month $k$.
Let $A_k=\frac{C_k}{k}$. This represents the average amount due over the first $k$ months.
In your second example, we have the $D$s being $0,0,600,160,0, 1200,1400,0,900,300,0,1800$. (All amounts dollars.)
So the $C$s (cumulative totals) are $0,0,600,760,760,1960,3360,3360,4260,4560,4560,6360$.
The $A$s are $0,\;0,\;200,\;190,\;152,\;326.67,\;480,\;420,\;473.33,\;456,\;414.55,\;530$
In this example, because the largest average is last, that amount ($530$) represents the amount you should deposit each month.
However, more generally, find the maximum $A_k$ and for the first $k$ months, deposit that amount. At the end of those $k$ months, you will have exactly paid off your loans through those $k$ months (with no leftover money saved for payments). Then recalibrate (in the same way) for the remaining months. Your subsequent deposit amounts will be lower. Depending on how many maximum averages you run into, you may have to recalibrate several more times.
Best Answer
Formally, indicating with $f_i$ the return function for the element $i \in N$, with $x_i$ the quantity allocated to $i$, and with $C$ your capital (i.e. 1 million) you have to solve the following problem:
$$\max \sum_{i=1}^N f_i(x_i) \;\;s.t.$$
$$\sum_{i=1}^N x_i = C$$
If you know the $f_i$ then you can try to use the Lagrange multipliers method (http://en.wikipedia.org/wiki/Lagrange_multiplier).
If otherwise the $f_i$ are unknown analytically (for example, the return is given by the result of a simulation), then you may look for heuristics (i.e. genetic algorithms, simulated annealing, or some kind of descent algorithms).