← 返回 pinterest 的题目列表Trip Expense Settlement
类型:online_judge
A group of friends go on a trip. Each friend may pay for others. The payments are recorded as an array of objects:
[
{ payer: 'alice', amount: 4000, payees: ['bob', 'jess', 'alice', 'sam'] },
{ payer: 'jess', amount: 2000, payees: ['jess', 'alice'] }
]
Each object contains:
payer: the person who paid
amount: total amount paid
payees: list of friends who share this expense
The goal is to compute the [minimal payments] required between friends to settle debts after the trip.
Example
Input:
[
{ payer: 'alice', amount: 4000, payees: ['bob', 'jess', 'alice', 'sam'] },
{ payer: 'jess', amount: 2000, payees: ['jess', 'alice'] }
]
Output:
[
{ payer: 'bob', amount: 1000, payees: ['alice'] },
{ payer: 'sam', amount: 1000, payees: ['alice'] }
]
Example
Input
[{'payer': 'alice', 'amount': 4000, 'payees': ['bob', 'jess', 'alice', 'sam']}, {'payer': 'jess', 'amount': 2000, 'payees': ['jess', 'alice']}]