DP + Slope Optimization (CDQ Divide and Conquer) --- [NOI2007] Currency Exchange

[NOI2007] Currency Exchange

Topic description:

 

Xiao Y recently worked in a gold securities exchange. The gold securities exchange only issues and trades two kinds of gold coupons: A commemorative coupons (hereinafter referred to as A coupons) and B commemorative coupons (hereinafter referred to as B coupons).

Every customer who holds a Gold Voucher has an account of his own. The number of gold coupons can be a real number.

 

With the ups and downs of the market every day, the two kinds of gold coupons have their own value at that time, that is, the amount of RMB that can be exchanged for each unit of gold coupons on that day.

We record the value of coupon A and coupon B on day K as \(A_{k}\) and \(B_{k}\) ​( yuan/unit gold coupon), respectively.

 

For the convenience of customers, the Gold Exchange provides a very convenient trading method: the proportional trading method.

 

The proportional trading method is divided into two aspects:

 

a) Selling golden coupons: The customer provides a real number OP in [0, 100] as the selling ratio, which means: convert OP% of A coupons and OP% of B coupons into RMB at the current value;

 

b) Buying gold coupons: The customer pays IP yuan, and the exchange will exchange the gold coupons with the total value of IP to the user.

And, the ratio of A coupons and B coupons to be provided to customers is exactly \(Rate_{k}\) on the Kth day  ;

 

For example, suppose the changes of \(A_{k}\)  , \(B_{k}\) ​, \(Rate_{k}\)  in the next 3 days are:

 

Time\(A_{k} \;\;B_{k}\;\;Rate_{k}\)

 

Day 1 1 1 1

 

Day 2 1 2 2

 

Day 3 2 2 3

 

Assume that on the first day, the user has 100 RMB in hand but does not have any gold coupons.

 

Users can perform the following actions:

 

Time User Action RMB (Yuan) A Quantity of Coupon B Quantity of Coupon

 

Account No 100 0 0

 

The first day to buy 100 yuan 0 50 50

 

Next day sell 50% 75 25 25

 

The next day buy 60 yuan 15 55 40

 

Day 3 Sell 100% 205 0 0

 

Note that multiple operations can be performed in the same day.

 

Xiao Y is a very economically minded employee. Through long-term operation and market measurement, he already knows the value of A and B coupons and the Rate in the next N days.

He also wants to be able to calculate the maximum amount of dollars that he can earn after N days if he starts with S dollars.

 

Input format:

The first line contains two positive integers N and S, which represent the number of days that small Y can predict and the amount of money initially owned.

Next N lines, K line three real numbers \(A_{k}\;\;B_{k}\;\;Rate_{k}\) , the meaning is as described in the title.

 

Output format:

There is only one real number MaxProfit, which represents the maximum amount of money that can be obtained at the end of the operation on the Nth day. Answer to 3 decimal places.

 

There is no partial score for this question. Only when the output of your program does not differ from the standard answer by more than \(10^{-3}\)  , can you get the full score of this test point, otherwise it will not be scored.

The test data is designed so that the precision error does not exceed \(10^{-7}\) .

For 40% of the test data, N ≤ 10;

For 60% of the test data, N ≤ 1 000;

For 100% of the test data, N ≤ 100 000;

For 100% test data, satisfy:

0 < \(A_{k}\) ≤ 10;

0 < \(B_{k}\) ≤ 10;

0 < \(Rate_{k}\) ≤ 100

MaxProfit ≤ \(10^{9}\) ;

The input file may be large, please use the fast read method.

 

Just translate the title.

I'll write a solution later. . . . . .

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324691557&siteId=291194637