S2P2 - Stock market
Mohamed is a rich man. He is dealing with stock market. Every day he starts with N dollars (specif budget). Through the day he can sell or buy if he sell he will gain S dollars and if he buy he will lose B dollars. Mohamed needs your help given his initial budget and amount he will gain if he sell stock , amount he will lose if he buy stock and sequence of actions sell or buy , print his total money after the day.
Input
input will contain 3 lines
First line : contain 3 integers N S B where 1<=N,S,B<=100000. N is initial budget , S is amount of sell , B amount for buy
Second line : contain 1 integer M where M is number of actions for the day, 1<=M<=100
thrid line : M charachters , each character will be B or S such that B represent buy and S represent sell
Output
print the mohamed total money after all day actions and if the amount of money < 0 just print 0.
print endl after the test case
Example
Input: 100 10 4
4
B B S B
Output: 98
Added by: | mohamed gamal |
Date: | 2012-01-27 |
Time limit: | 2s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | C++ 4.3.2 CPP |