#P4027. [NOI2007] 货币兑换

    ID: 2959 远端评测题 1000ms 128MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>2007NOI 系列Special Judge分治斜率优化凸包

[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 KK as AKA_K and BKB_K (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 OPOP in [0,100][0, 100] as the selling ratio, meaning: exchange OP%OP\% of A vouchers and OP%OP\% of B vouchers into RMB at the current values.

b) Buy vouchers: The customer pays IPIP RMB, and the exchange will convert it into vouchers with a total value of IPIP, and the proportion of A and B vouchers provided to the customer will be exactly RateK\mathrm{Rate}_ K on day KK.

For example, suppose over the next 33 days the changes of AKA_K, BKB_K, and RateK\mathrm{Rate}_ K are as follows:

Time AKA_K BKB_K RateK\mathrm{Rate}_ K
Day 1 11 11
Day 2 22 22
Day 3 22 33

Assume that on day 1, the user has 100100 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 100100 00
Day 1 Buy 100100 yuan 00 5050
Day 2 Sell 50%50\% 7575 2525
Buy 6060 yuan 1515 5555 4040
Day 3 Sell 100%100\% 205205 00

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 Rate\mathrm{Rate} for the next NN days. He also wants to compute, if he starts with SS RMB yuan, what is the maximum amount of money he can obtain after NN days.

Input Format

The first line contains two positive integers N,SN, S, representing the number of days Xiao Y can foresee and the initial amount of money, respectively.

The next NN lines each contain three real numbers AK,BK,RateKA_K, B_K, \mathrm{Rate} _ K on line KK, as described above.

Output Format

Output a single real number MaxProfit\mathrm{MaxProfit}, the maximum amount of money obtainable by the end of day NN. The answer should be rounded to 33 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 100100 00
Day 1 Buy 100100 yuan 00 5050
Day 2 Sell 100%100\% 150150 00
Buy 150150 yuan 00 7575 37.537.5
Day 3 Sell 100%100\% 225225 00

There is no partial credit for this problem. Your program’s output must not differ from the standard answer by more than 0.0010.001 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 10710^{-7}.

For 40%40\% of the testdata, N10N \le 10.

For 60%60\% of the testdata, N1000N \le 1\,000.

For 100%100\% of the testdata, N105N \le 10^5.

For 100%100\% of the testdata, the following hold: 0<AK100 < A_K \leq 10, 0<BK100 < B_K \le 10, 0<RateK1000 < \mathrm{Rate}_K \le 100, MaxProfit109\mathrm{MaxProfit} \leq 10^9.

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