National Olympiad in Informatics, China, 2007
Little Y has recently been working at a currency exchange center. The currency exchange center only offers two types of vouchers to be exchanged: commemorative voucher A (henceforth known as voucher A) and commemorative voucher B (henceforth known as voucher B). All voucher-holding customers possess their very own account. The quantity of vouchers a customer has may be a real number.
Rising and falling daily with the waves of the market, the two types of
vouchers each has their own values at any given time, and each unit of a
voucher can be traded that day for some amount of cash. We note that on
day
To make it more convenient for customers, the exchange center offers a very easy system to make transactions: the ratio exchange method. There are two different aspects to the ratio exchange method:
- Selling vouchers: the customer provides a real number
in the range as the selling ratio. This means that of voucher A and of voucher B are exchanged for cash with the rate at that point in time. - Buying vouchers: the customer pays
dollars, and the exchange center takes this money to exchange it for vouchers. Furthermore, the ratio between the value of voucher A and voucher B on day just happens to be .
For example, let's assume for the next 3 three days the following
changes in the values of
Time | |||
---|---|---|---|
Day 1 | |||
Day 2 | |||
Day 3 |
Let's say that on one day, a customer has
Time | Transaction | Cash (Dollars) | Voucher A | Voucher B |
---|---|---|---|---|
Initial | None | |||
Day 1 | Buy — |
|||
Day 2 | Sell — |
|||
Day 2 | Buy — |
|||
Day 3 | Sell — |
Note that there may be multiple transactions on a single day.
Little Y is a very economically-minded worker. After a relatively long
time conducting operations and market estimates, he already knows within
the future
Input Specification
The first line contains two positive integers
Within the next
Output Specification
Output a single real number
Sample Input
3 100
1 1 1
1 2 2
2 2 3
Sample Output
225.000
Explanation
Time | Transaction | Cash (Dollars) | Voucher A | Voucher B |
---|---|---|---|---|
Initial | None | |||
Day 1 | Buy — |
|||
Day 2 | Sell — |
|||
Day 2 | Buy — |
|||
Day 3 | Sell — |
Constraints
The test data ensures that the precision needed for calculations will
not exceed
For
For
For
For
; ; ; .
Hints
The input may be very large, please use faster methods of input.
There must be an optimal series of transaction satisfying the
conditions:
- each buying transaction uses up all of the cash, and
- each selling transaction sells all of the vouchers.
Problem translated to English by .
Comments