equality – Calculate transfers to equalize balances?

I’m playing a MMORPG where we party hunt, the problem is that at the end of the hunt each person may have different balances depending on what items they wasted and the stuff each one looted.

The game tell us what are our balances in the party, but nothing more… so for example, having something like this as an input:


  • Person A: +132
  • Person B: -50
  • Person C: +70

I want to obtain the transfers to be made so that we all end up with the same balance, using the example from above:


  • Person A should transfer 81 to B
  • Person C should transfer 20 to B

So A ends up with 51, B ends up with 51 and C ends up with 50.

Is there a known algorithm for this? I would like to make a web app with this calculator.