
ZOJ Problem Set  3567
The capital stock (or just stock) of a business entity represents the original capital paid into or invested in the business by its founders. It serves as a security for the creditors of a business since it cannot be withdrawn to the detriment of the creditors. Stock is distinct from the property and the assets of a business which may fluctuate in quantity and value. SXSTAR found that MA5 and MA10 are important indicators for buying and selling stock. For this problem, you need to know the following technical terms:
SXSTAR is so busy that he does not have time to watch the price volatility. He developed an autotransaction system to help him buy or sell stock. First day, he put M yuan on the system. From the 10th day, the system auto calculates the MA5 and MA10 after all transactions every day. If MA5 > MA10 today, and MA5 <= MA10 yesterday, the system will buy this stock, as much as possible, at tomorrow's opening price. On the other hand, If MA5 <= MA10 today, and MA5 >= MA10 yesterday, the system will sell all this stock at tomorrow's opening price. SXSTAR wants to know during D days, how much money he can earn if he must sell out all the stock at closing price of the Dth day. Could you help him to figure it out? Input There are several test cases (<=200). You should process to the end of input. For each test case, there are two parts. The first part has two lines. The first line has two integers D (0 <= D <= 10000) and Ticker Symbol (indicates the code of stock SXSTAR would buy). The second line has one real number M (0 <= M <= 100000000). The second part has D lines, the ith line has two real numbers O_{i} (0 <= O_{i} <= 100000000) and C_{i} (0 <= C_{i} <= 100000000), indicating the ith day's opening price and closing price. Output For each case, you should print a single line with the money he could earn after D days. Your answer should include two decimal places as the definition of Unit Price. Each fee mentioned above should round to 0.01 yuan and be deducted directly from the account balance when the transaction happens. Whenever, the balance of the account should not less than 0. Sample Input 2 000001 100 100 100 120 120 Sample Output 0.00 Author: SHEN, Xin Contest: ZOJ Monthly, December 2011 