#P4027. [NOI2007] 货币兑换
[NOI2007] 货币兑换
Description
Xiao Y (pinyin) recently started working at a voucher exchange. This exchange issues and trades only two types of vouchers: A commemorative voucher (hereinafter A voucher) and B commemorative voucher (hereinafter B voucher). Each customer who holds vouchers has their own account. The quantities of vouchers can be real numbers.
With daily market fluctuations, the two vouchers each have their current value, i.e., each unit of voucher can be exchanged for a certain amount of RMB on that day. We record the values of A and B vouchers on day as and (yuan per unit voucher), respectively.
For customer convenience, the exchange provides a very convenient trading method: proportional trading.
Proportional trading has two aspects:
a) Sell vouchers: The customer provides a real number in as the selling ratio, meaning: exchange of A vouchers and of B vouchers into RMB at the current values.
b) Buy vouchers: The customer pays RMB, and the exchange will convert it into vouchers with a total value of , and the proportion of A and B vouchers provided to the customer will be exactly on day .
For example, suppose over the next days the changes of , , and are as follows:
| Time | |||
|---|---|---|---|
| Day 1 | |||
| Day 2 | |||
| Day 3 | |||
Assume that on day 1, the user has RMB yuan and no vouchers.
The user can perform the following operations:
| Time | User operation | RMB (yuan) | Quantity of A vouchers | Quantity of B vouchers |
|---|---|---|---|---|
| Account opening | None | |||
| Day 1 | Buy yuan | |||
| Day 2 | Sell | |||
| Buy yuan | ||||
| Day 3 | Sell | |||
Note that multiple operations can be performed on the same day.
Xiao Y is financially savvy. Through long-term operations and market estimation, he already knows the values of A and B vouchers and for the next days. He also wants to compute, if he starts with RMB yuan, what is the maximum amount of money he can obtain after days.
Input Format
The first line contains two positive integers , representing the number of days Xiao Y can foresee and the initial amount of money, respectively.
The next lines each contain three real numbers on line , as described above.
Output Format
Output a single real number , the maximum amount of money obtainable by the end of day . The answer should be rounded to decimal places.
3 100
1 1 1
1 2 2
2 2 3
225.000
Hint
| Time | User operation | RMB (yuan) | Quantity of A vouchers | Quantity of B vouchers |
|---|---|---|---|---|
| Account opening | None | |||
| Day 1 | Buy yuan | |||
| Day 2 | Sell | |||
| Buy yuan | ||||
| Day 3 | Sell | |||
There is no partial credit for this problem. Your program’s output must not differ from the standard answer by more than to receive full credit for a test point; otherwise, you get no points.
The testdata is designed such that the precision error will not exceed .
For of the testdata, .
For of the testdata, .
For of the testdata, .
For of the testdata, the following hold: , , , .
The input file may be large; please use fast I/O.
There always exists an optimal buy/sell strategy that satisfies: each buy operation uses up all RMB, and each sell operation sells all vouchers.
Translated by ChatGPT 5
京公网安备 11011102002149号