Create a lightweight banking system that handles requests in timestamp order, where timestamps never go backward. It must provide account creation, deposits, transfers, cashback-enabled payments, payment lookups, account consolidation, and spender rankings.
Read the requests from standard input, then write one result per request to standard output.
The first input line gives an integer Q, representing the total number of operations.
Each of the following Q lines contains exactly one request:
CREATE timestamp accountId
DEPOSIT timestamp accountId amount
TRANSFER timestamp sourceAccountId targetAccountId amount
PAY timestamp accountId amount
GET_PAYMENT_STATUS timestamp accountId paymentId
MERGE timestamp accountId1 accountId2
TOP_SPENDERS timestamp n
timestamp is an integer, and request timestamps are in non-decreasing order.accountId is a space-free string.amount is a non-negative integer. A TRANSFER or PAY can succeed only when its amount is positive.CREATE timestamp accountIdOpen an account whose initial balance is 0.
true when no account with that id currently exists.false when an active account already uses that id.DEPOSIT timestamp accountId amountAdd amount to the specified account.
-1.TRANSFER timestamp sourceAccountId targetAccountId amountMove amount from sourceAccountId to targetAccountId.
A transfer is valid only when all of the following hold:
amount;amount > 0When it succeeds:
amount;amount;amount;If any condition fails, print -1.
PAY timestamp accountId amountCharge amount from an account and create a payment identifier.
A payment may be completed only if:
amount;amount > 0For a successful payment:
amount from the account balance;amount to that account's cumulative outgoing amount;payment1, payment2, and so on, increasing globally across successful payments;timestamp + 86400000, equal to floor(amount * 2 / 100);For an unsuccessful payment, print an empty string, meaning a blank line.
Before handling each request, process every scheduled cashback with a scheduled time no later than the current timestamp.
GET_PAYMENT_STATUS timestamp accountId paymentIdRetrieve the current state of a payment.
IN_PROGRESS when its cashback has not yet been credited.CASHBACK_RECEIVED once its cashback has been credited.When the account that originally made a payment has subsequently been merged into another account, that payment is associated with the resulting active account.
MERGE timestamp accountId1 accountId2Combine accountId2 into accountId1.
The merge is allowed only when:
After a successful merge:
accountId2's balance to accountId1;accountId2's cumulative outgoing amount to accountId1;accountId2 are eventually added to accountId1;accountId2 as payments belonging to accountId1;accountId2 inactive so it can no longer be used directly.Print true if the merge completes; otherwise, print false.
TOP_SPENDERS timestamp nList up to n active accounts with the greatest cumulative outgoing amount.
Apply these ordering rules:
accountId first.Use this output layout:
accountId1(totalOutgoing1), accountId2(totalOutgoing2)
When fewer than n accounts are active, output every active account.
1 <= Q <= 200000
1 <= len(accountId) <= 50
0 <= timestamp <= 10^18
0 <= amount <= 10^12
1 <= n <= 100000
10
CREATE 10 cedar
CREATE 11 maple
DEPOSIT 12 cedar 900
TRANSFER 13 cedar maple 250
PAY 14 maple 120
GET_PAYMENT_STATUS 15 maple payment1
MERGE 16 cedar maple
GET_PAYMENT_STATUS 17 cedar payment1
TOP_SPENDERS 18 2
DEPOSIT 86400014 cedar 0
true
true
900
650
payment1
IN_PROGRESS
true
IN_PROGRESS
cedar(370)
782
The transfer contributes 250 to cedar's outgoing total, and the payment contributes 120 to maple's total; merging produces cedar's total of 370. The payment's cashback is 2, which is credited at timestamp 86400014, changing cedar's balance from 780 to 782 before the final deposit.
Input:
6
CREATE 21 red
CREATE 22 blue
DEPOSIT 23 red 80
TRANSFER 24 red blue 20
TRANSFER 25 red green 5
TOP_SPENDERS 26 2
Output:
true
true
80
60
-1
red(20), blue(0)
The first transfer succeeds and records 20 as red's outgoing amount, while the second fails because green is not an active account.