I am affiliated with a business that pays subcontractors based on the job. The total job payment is a set amount, but how much goes to which contractor is variable based on how much time the contractor put in, and what their value relative to the other contractor is. I'm having a difficult time writing a formula that can calculate that without getting into circular reasoning.

For example I have $4000 to pay out on a Job. Trinity had 20 hours, TFT had 40 hours, and Hanson had 40 hours. Trinity and TFT are paid at the same rate, Hanson is paid at half of whatever they are making. I can manually enter percentages until I get that figured out, but I would like to have a formula to do it for me, so that when I enter a new total price and everyone's hours and percentage, it calculates it correctly.

This is very easy to do when everyone is getting paid at the same rate, but when some contractors are more valuable than others, and their percentage of the hours are fluctuating, I haven't yet gotten it.

I attached my manual version.