Submit Best Submissions All Submissions

180. Rami The Accountant

Problem Statement:
Rami is a very lazy accountant. All day at his job, he sits and calculates his clients' accounts.

Every client has some starting amount of money. He does some transactions (buying and selling things). Each transaction is described with a word (either buy, or sell) and a number which is the price.

As Rami is too lazy to do this operations all by himself, and as he has too many clients, he asked your help. Your job is to write a program to calculate the final amount of money for each client after all the transactions are done.

Input Format:
The first line of input has one integer N, which is the number of clients Rami has. Next are the details about N clients. ( 1 ≤ N ≤ 100 )

Each client details start with a single word representing the name of the client (only English alphabet a-z, A-Z, 30 character max).

The next line has two integers: S and k. S is the starting amount of money for the client and k is the number of transactions this client has made.

( 0 ≤ S ≤ 106 )

( 1 ≤ k ≤ 1000 )

k lines follow, each line with either "sell" or "buy" and an integer xi which is the price.

( 0 ≤ x ≤ 106 )

Output Format:
For each client output a single line with the name of the client and the amount of money he finally has.

Sample Input:
2 Kareem 500 2 buy 200 sell 50 Rama 1000 3 buy 100 buy 500 buy 200

Sample Output:
Kareem 350 Rama 200

Added by: samiemad
Added at: 2014-07-26 09:00:12 UTC
Time Limit: 1 second
Partial score: No
Source:Practical C++ and Algorithms Course, Level 1, By. Sami EMAD