#C1828. Transaction Processor

    ID: 45076 Type: Default 1000ms 256MiB

Transaction Processor

Transaction Processor

You are given a list of users with their initial balances and a series of transactions. Each transaction is one of the following types:

  • DEPOSIT <username> <amount>: Increase the user's balance by amount.
  • WITHDRAW <username> <amount>: Decrease the user's balance by amount, but only if the user has enough funds.
  • TRANSFER <from_user> <to_user> <amount>: Transfer amount from one user to another if the sender has sufficient funds.

For a deposit, the new balance is computed as \(balance_{new} = balance_{old} + amount\). For a withdrawal, it is only performed if \(balance_{old} \ge amount\). For a transfer, the sender's balance is reduced and the receiver's balance is increased by the same amount, provided \(balance_{sender} \ge amount\).

After processing all transactions, output the updated list of users sorted lexicographically by their names along with their final balances.

inputFormat

The input is given from standard input in the following format:

N
name1 balance1
name2 balance2
... (N lines)
M
transaction1
transaction2
... (M lines)

Where:

  • N is the number of users.
  • Each of the next N lines contains a user's name and their balance (a floating-point number), separated by a space.
  • M is the number of transactions.
  • Each of the next M lines is a transaction in one of the three formats described above.

outputFormat

Print the updated balances of all users to standard output, one user per line, in ascending order of their names. Each line should contain the user's name and their balance separated by a space. The balance should be printed as a floating-point number.

## sample
3
Alice 500.0
Bob 300.0
Charlie 400.0
4
DEPOSIT Bob 200
WITHDRAW Alice 100
TRANSFER Charlie Bob 50
WITHDRAW Charlie 500
Alice 400.0

Bob 550.0 Charlie 350.0

</p>