Logu -4027 NOI2007 Currency exchange __noi

Source: Internet
Author: User
Topic Description

Little Y recently worked on a gold coupon exchange. The gold Stock Exchange only issues two kinds of gold coupons: a commemorative coupon (hereinafter referred to as a voucher) and a B commemorative coupon (hereinafter referred to as B coupons). Every customer who holds a gold coupon has an account of his or her own. The amount of gold coupons can be a real number.

Every day with the fluctuation of the market, both kinds of gold coupons have their own value at that time, that is, the number of RMB per unit of the day can be exchanged. We record the value of a and B coupons in the K-day respectively for Aka_kak and BKB_KBK (yuan/unit gold coupons).

For the convenience of customers, the Golden Coupon Exchange provides a very convenient way of trading: proportional trading law.

The proportional trading law is divided into two aspects:

A) the sale of Gold Coupons: Customers provide a [0,100] real number OP as a selling ratio, the meaning is: the op% of a coupons and op% B coupons to the value of the current exchange for RMB;

b) Buy gold coupons: Customers pay the IP yuan, the exchange will be exchanged to the user's total value of the gold coupons, and to meet the customer's a coupon and B coupons in the proportion of K-day just for Ratekrate_kratek;

For example, assume that the Aka_kak, BKB_KBK, Ratekrate_kratek changes in the next 3 days are

time Aka_kak bkb_kbk Ratekrate_kratek

First day 1 1 1

Two days 1 2 2

third day 2 2 3

assume that in the first days, the user has 100 yuan in hand but no gold coupons.

the user can perform the following actions:

time user Operation RMB (yuan) a voucher quantity of the number of B coupons open

0 0 The

first day to buy 100 $0 The

next day to sell 50% 25
  
    > The next day, buy $60 on the

third day and sell 100% 205 0 0

  

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

Small Y is a very economic minded staff, through a longer period of operation and market estimates, he has known the next N days of the value of a and B coupons and Rate. He also wanted to be able to figure out how much money would be available to N days after he had the S dollar at the beginning. input and output formats

Input Format:

The first line of two positive integers N, S, respectively, represents the number of days that small Y can predict and the amount of money that is initially available.

The next N rows, K line three real Aka_kak, BKB_KBK, Ratekrate_kratek, meaning as described in the topic.

output Format:

There is only one real maxprofit that represents the maximum amount of money that can be obtained at the end of the nth day operation. The answer retains 3 decimal places. input and Output sample

Enter Sample #:

3 100
1 1 1
1 2 2
2 2 3

Output Sample #:

225.000 Description

Time user operation quantity of a coupon in RMB (yuan) number of B coupons

Open Account No 100 0 0

Buy 100 $0 50 50 on the first day

The next day sold 100% 150 0 0

The next day buy 150 Yuan 0 75 37.5

The third day sold 100% 225 0 0

There is no part of the point, your program output only and the standard difference is not more than 0.001, in order to obtain the test points of full marks, otherwise do not score.

The test data design makes the accuracy error not exceed 10−7 10−7 10^{-7}.

For 40% of the test data, to meet n≤10;

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

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

For 100% of the test data, meet:

0 < AK A K a_k≤10;

0 < BK B K b_k≤10;

0 < Ratek R a T e K rate_k≤100

Maxprofit M A x P r o f i t maxprofit≤10910^9109;

The input file may be large, please use a quick read.

there must be an optimal business solution to meet:

use all RMB for each purchase operation;

sell all the gold coupons each time you sell. You might not believe it, I thought it was buying stocks, and I could only buy and sell the whole integer.

Seriously do it should be balanced tree maintenance convex bag, but I do not understand (a may also go to see)
So I did it in accordance with CDQ paper. simply: cdq+ slope optimization

Don't worry about which day's money to buy one day's currency, just consider the exchange after the currency on which day to change it (this is a nonsense, logical confusion and no need to read)

Consider the I/I day selling currency (in terms of buying stocks)
It is worth mentioning, then, that the time to obtain a currency can only be [1,i−1] [1, i−1] [1,i-1]
Suppose that I I I day in the hands of the amount of money for x[i],y[i] X [i], Y [i] x[i],y[i], the maximum gain for f[i] f [i] f[i]
Currency exchange for Ca[i],cb[i] C A [i], C B [i] ca[i],cb[i]

So the first I I day the amount of money to exchange for
ca[i]=f[i]/(Ai

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.