Who owes who money optimization

后端 未结 10 1281
暗喜
暗喜 2020-12-14 02:18

Say you have n people, each who owe each other money. In general it should be possible to reduce the amount of transactions that need to take place. i.e. if X owes Y £4 and

10条回答
  •  臣服心动
    2020-12-14 02:59

    Are people required to clear their debts by paying somebody that they actually owe money to personally? If not, the following seems to work suspiciously easily:

    For each person, work out the net amount they should pay, or should receive.

    Have somebody who owes money net pay somebody who should receive money net min(amount owed, amount to be received). After this, at least one of the two participants owes nothing and should receive nothing, and so can be removed from the problem.

    Assuming I have missed something, what are the constraints that apply (or gross error made)?

提交回复
热议问题