Account Balance
You are working for the financial institution CBank, and you have been tasked with writing a module that will take an initial account balance, along with a list of that day's transactions, and return the ending balance for the day. Each transaction will be either a credit, which adds funds to the account, or a debit, which removes funds from the account. If a debit exceeds the available funds at the time, then the account balance will go negative. You will be given the initial account balance. You will also be given the the list of transactions for the day. Each element of transactions will be in the form "type amount" (quotes added for clarity). Each type will be 'C' or 'D', for credit or debit, respectively. Each amount will be an integer between 1 and 1000000, inclusive, with no leading zeros. You must print an integer representing the ending balance after processing all of the transactions.
Especificación de entrada
The first line of the input is , the number of test cases for this problem. Each scenario begins with a line containing an integer
, initial account balance for the day. The following line have an integer
, the number of transactions for the day. In each of the T following lines, there is a single transaction.
Especificación de salida
For each test case output a single line with an integer B, representing the ending balance of the day.
Ejemplo de entrada
3
100
3
C 1000
D 500
D 350
100
0
100
3
D 50
D 20
D 40
Ejemplo de salida
250
100
-10
Comments