Optimization technique for iterative distribution
It looks like a resource allocation problem. I can't think of any statistical method which would help here, but maybe there is.
I think the process can be simplified by first calculating the amount in excess and in &quot;shortage&quot;. I don't know if there's a formal method for this but I would try something like the following:

Distribute $a$ based on the weights. Then calculate for every entity:

its excess amount: X has 0, Y has 15 (75-60)
its missing amount: X has 0, Y has 0.
its capacity for additional amount. X has 15 (40-25) and Y has 0.
its capacity for giving away some amount. X has 15 (25-10) and Y has 20 (60-40)


Calculate the sum of excess amount $S_{excess}$, sum of missing amount $S_{missing}$, and capacity $S_{plus}$, $S_{minus}$. Let $S = S_{excess} - S_{missing}$:

If $S&gt;0$

If $S&gt;S_{plus}$, then no solution
Otherwise (1) fill every entity which has amount missing to their minimum, (2) distribute amount S by filling any entity which has capacity for more.


If $S&lt;0$

If $|S|&gt;S_{minus}$, then no solution.
Otherwise (1) unload every entity which has amount in excess to their maximum, (2) take total amount |S| from any entity which capacity for giving away.





If I'm not mistaken this requires only two steps, each step going over all the entities.