I was recently asked to calculate the money owed amongst a group of people who went on a trip together and came upon an interesting problem: given that
Take a look at this blog article, "Optimal Account Balancing", goes over your problem exactly.