← 返回 capitalone 的题目列表Simple Bank System (Withdraw/Deposit/Transfer)
类型:online_judge
Problem: Simple Bank System (Withdraw/Deposit/Transfer)
You are given an array balance of length n where balance[i] is the balance of account i+1 (accounts are 1-indexed).
Process a sequence of operations:
withdraw(account, money)
deposit(account, money)
transfer(account1, account2, money)
Validation
Any account id must be within [1, n], otherwise the operation fails.
withdraw: fails if balance[account-1] < money.
transfer: fails if balance[account1-1] < money.
deposit: no balance constraint.
Output
A common OA variant: process operations in order; if any operation fails, output -1. Otherwise output the final balances.
Suggested input format
Line 1: integer n
Line 2: n integers balance
Line 3: integer q
Next q lines: withdraw a x, deposit a x, or transfer a b x
Constraints
1 <= n, q <= 2 * 10^5
0 <= balance[i], money <= 10^9
Example
Input
3
10 5 20
3
withdraw 2 3
deposit 3 10
transfer 1 3 5
Output
5 2 35