You are building a simple ledger.
Inputs
-
A list of account names.
-
An initial balance for each account.
-
A list of transfer transactions, each with:
-
from
(sender)
-
to
(receiver)
-
amount
(positive integer)
-
A transaction fee rule: each successful transfer charges the sender a
fixed fee
fee
(positive integer) in addition to the transferred
amount
.
Processing rules
For each transaction in order:
-
A transaction is
accepted
only if the sender has at least
amount + fee
available at that moment.
-
If accepted:
-
Subtract
amount + fee
from
from
.
-
Add
amount
to
to
.
-
If rejected:
-
Do not change any balances.
-
Record the rejected transaction in a rejection list.
Output
-
Print (or return) the final balances for
only
the accounts whose final balance is
not 0
.
-
Return the
rejection list
(all rejected transactions, in original order).
Constraints
-
Up to 10^5 transactions.
-
Account count up to 10^5.
-
Amounts and balances fit in 64-bit signed integers.
Notes
-
If an account name appears in a transaction but was not in the initial list, treat its initial balance as 0.
-
You may output balances in any deterministic order (e.g., sorted by account name) as long as it is specified and consistent.