RampOA #2
Bot Bank — Deposit/Withdraw with Cashback (Stateless solution)
Estimated MediumJudge-ready
Topics (AI-labelled)SimulationHashing
Process bank deposits and withdrawals in time order. A successful withdrawal refunds 2% of the withdrawn amount (rounded down) 24 hours later; when a cashback is due, apply it before processing a request in the same second. At the first request with an invalid account or insufficient balance, return the negative of its 1-based request index.
Input
The first line contains N Q (on this site: 1≤N≤100000, 0≤Q≤200000); the second line contains N initial non-negative balances (each ≤10^12). Then Q lines follow: operation timestamp holder_id amount. operation is deposit or withdraw; timestamp is a strictly increasing positive integer number of seconds (≤10^12); amount is a non-negative integer (≤10^9); holder_id is an integer, where 1..N are valid accounts and any other value is treated as an invalid account, as the problem specifies.
Output
Output a JSON integer array. If all requests are valid, return the account balances after the last request's timestamp has been processed; if request i is the first invalid one, output [-i]. Cashbacks that only become due after the last request are not included in the final balances.
Example 1
Input:
1 2
200
withdraw 1 1 100
withdraw 86401 1 100
Output:
[2]
Example 2
Input:
1 1
49
withdraw 1 1 49
Output:
[0]
Example 3
Input:
1 1
100
deposit 1 0 1
Output:
[-1]
Example 4
Input:
1 1
49
withdraw 1 1 50
Output:
[-1]
Example 5
Input:
1 2
100
deposit 1 1 5
withdraw 2 2 1
Output:
[-2]
Example 6
Input:
1 1
100
withdraw 1 1 100
Output:
[0]
Example 7
Input:
1 2
100
withdraw 1 1 100
deposit 86402 1 5
Output:
[7]
Example 8
Input:
2 2
10 10
deposit 1 1 3
withdraw 2 2 10
Output:
[13,0]
Example notes
Use a min-heap to manage cashback due times.
Editorial
Loading solution…