Bank

0

0 votes
Easy
Problem

Lulu is monitoring her bank transactions in a particular account. She asked you to write her a program that will automate the computations for her. She wants a simple program that would keep track of the account’s maintaining and current balances. It should also be able to update the current balance based on the following transactions:

  1. Deposit – add amount to current balance.
  2. Withdraw – deduct amount from current balance.

She likewise tells you that withdrawals should only be allowed if it won’t cause the current balance’s amount go below the maintaining balance.

INPUT FORMAT

Input begins with an integer M denoting the maintaining balance for the account

The second line of input is an integer B denoting her account’s current balance.

The third line contains an integer N indicating how many transactions follow.

Succeeding lines are N character c and integer a pairs, one in each line, denoting the transactions that will be done to Lulu’s bank account, where c is either ‘D’ or ‘W’ for “Deposit” and “Withdrawal”, respectively; and n is the amount to be deposited or withdrawn.

OUTPUT FORMAT

For each transaction, display the updated current balance. If withdrawing an amount will cause the current balance’s value to go below the maintaining balance, print “Cannot withdraw!”. Output should be separated by a new line.

CONSTRAINTS

500 <= M <= 10000
500 <= C <= 100000
1 <= N <= 100
C is either ‘D’ or ‘W’
1 <= a <= 10000

Time Limit: 5
Memory Limit: 256
Source Limit:
Editor Image

?