Big Stonks

Time limit: 2s Memory limit: 256MB Input: Output:

Since he learned Rust, Dario is now able to write software that would have never been possible with inferior languages such as C/C++. For example, he recently wrote a software that can predict with perfect accuracy the stock market prices for the next N days. Knowing these prices, he is now looking for a strategy that will make him rich.

Dario selected KK individual stocks, and for each of them he computed the buying price BB and selling price SS for each of the NN consecutive days. For example, let’s say that Dario’s list contains K=3K = 3 stocks ([A]pple, [F]acebook, [G]oogle) and that he computed their prices for N=2N = 2 consecutive days:

Day Buy [A] Sell [A] Buy [F] Sell [F] Buy [G] Sell [G]
1 5 3 6 2 5 4
2 8 6 7 6 6 5

The prices in the list are expressed in Euro, and are always integers. The total starting budget that Dario can invest is 11 Euro. For the purpose of this problem, we assume that it’s possible to buy any fraction of a stock (e.g. you could buy 15\frac{1}{5} of an Apple stock on the first day for 11 Euro). Help Dario find the maximum profit that he can make by optimally investing 11 Euro over those NN days.

Input data

The first line contains two integers NN and KK.

NN lines follow: the ii-th line contains KK pairs of integers: the buying price Bi,jB_{i,j} and selling price Si,jS_{i,j} for the jj-th stock on the ii-th day.

Output data

You need to write a single line with a number: the maximum possible amount of Euro that Dario can have at the end of the NN days. The answer will be considered correct if the absolute or relative error is lower than 10610^{−6}.

Constraints and clarifications

  • 1N,K3 0001 \leq N, K \leq 3 \ 000;
  • 1Si,jBi,j1001 \leq S_{i,j} \leq B_{i,j} \leq 100;
  • It is guaranteed that the answer will fit in a 6464 bit floating point variable (double).
# Score Constraints
1 0 Examples
2 25 K=1K = 1
3 42 N,K300N, K \leq 300
4 33 No additional limitations.

Example 1

stdin

2 3
5 3 6 2 5 4
8 6 7 6 6 5

stdout

1.2

Explanation

In the first sample case, Dario can buy 15\frac{1}{5} of the first stock on the first day (when it costs 55 Euro) and sell it on the second day (when it sells for 66 Euro), scoring 156\frac{1}{5} \cdot 6 = 1.201.20 Euro.

Example 2

stdin

3 3
5 3 6 2 5 4
8 6 7 6 6 5
14 13 15 14 11 9

stdout

2.6

Explanation

In the second sample case note that first two days are unchanged. One almost-optimal strategy in this case would be to reinvest the 1.201.20 Euro of the second day by buying 1.27\frac{1.2}{7} = 0.17142857140.1714285714 units of the second stock, which can be sold on the last day for 1.2714\frac{1.2}{7} \cdot 14 = 2.402.40 Euro. However, there is an even better solution: keep the 15\frac{1}{5} units of the first stock bought on the first day, and sell it on the third day for 1513\frac{1}{5} \cdot 13 = 2.602.60 Euro!

Log in or sign up to be able to send submissions!