Welcome to ZOJ
Select Problem
ZOJ Problem Set - 3567
Stock IV

Time Limit: 2 Seconds      Memory Limit: 65536 KB

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:

  • Ticker Symbol: Each stock has its own code with six digits, such as 600000 for Shanghai Pudong Development Bank. The code for Shanghai Market starts with digit 6, and the one for Shenzhen Market starts with digit 0.
  • Stamp Duty: When you sell out your stock, you should pay 0.1% of turnover to the government as stamp duty.
  • Fee: When you buy in or sell out your stock, you should pay 0.3% of turnover to the brokerage as the fee. Each transaction should pay 5 yuan at least.
  • Transfer Fee: When you buy in or sell out your stock in Shanghai Market, you should pay 1 yuan for each 1000 shares, and the part of less than 1000 shares should be calculated as 1000 shares
  • Unit Price: The smallest unit price of stock is 0.01 yuan each share.
  • Unit Share: The smallest unit of buying share is one hundred shares, also called one hand.
  • Opening Price: The first transaction price on one day.
  • Closing Price: The last transaction price on one day.
  • MA5: The average closing price of recent 5 days.
  • MA10: The average closing price of recent 10 days.
  • T+1 Rule: If you buy a stock at Tth day, you cannot sell it at Tth day. You can sell it at (T+1)th day or later. This problem adopts T+1 Rule.

SXSTAR is so busy that he does not have time to watch the price volatility. He developed an auto-transaction 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?


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 Oi (0 <= Oi <= 100000000) and Ci (0 <= Ci <= 100000000), indicating the ith day's opening price and closing price.


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
120 120

Sample Output


Author: SHEN, Xin
Contest: ZOJ Monthly, December 2011
Submit    Status