CF1178H Stock Exchange
Description
Warning: This problem has an unusual memory limit!
Bob decided that he will not waste his prime years implementing GUI forms for a large corporation and instead will earn his supper on the Stock Exchange Reykjavik. The Stock Exchange Reykjavik is the only actual stock exchange in the world. The only type of transaction is to take a single share of stock $ x $ and exchange it for a single share of stock $ y $ , provided that the current price of share $ x $ is at least the current price of share $ y $ .
There are $ 2n $ stocks listed on the SER that are of interest to Bob, numbered from $ 1 $ to $ 2n $ . Bob owns a single share of stocks $ 1 $ through $ n $ and would like to own a single share of each of $ n+1 $ through $ 2n $ some time in the future.
Bob managed to forecast the price of each stock — in time $ t \geq 0 $ , the stock $ i $ will cost $ a_i \cdot \lfloor t \rfloor + b_i $ . The time is currently $ t = 0 $ . Help Bob find the earliest moment in time in which he can own a single share of each of $ n+1 $ through $ 2n $ , and the minimum number of stock exchanges he has to perform in order to do that.
You may assume that the Stock Exchange has an unlimited amount of each stock at any point in time.
Input Format
The first line contains a single integer $ n $ ( $ 1 \leq n \leq 2200 $ ) — the number stocks currently owned by Bob.
Each of the next $ 2n $ lines contains integers $ a_i $ and $ b_i $ ( $ 0 \leq a_i, b_i \leq 10^9 $ ), representing the stock price of stock $ i $ .
Output Format
If it is impossible for Bob to achieve his goal, output a single integer $ -1 $ .
Otherwise, output two integers $ T $ and $ E $ , where $ T $ is the minimum time in which he can achieve his goal, and $ E $ is the minimum number of exchanges in which he can achieve his goal at time $ T $ .
Explanation/Hint
In the first example, Bob simply waits until time $ t = 3 $ , when both stocks cost exactly the same amount.
In the second example, the optimum strategy is to exchange stock $ 2 $ for stock $ 1 $ at time $ t = 1 $ , then exchange one share of stock $ 1 $ for stock $ 3 $ at time $ t = 5 $ (where both cost $ 15 $ ) and then at time $ t = 6 $ exchange the second on for the stock number $ 4 $ (when they cost $ 18 $ and $ 17 $ , respectively). Note that he can achieve his goal also with only two exchanges, but this would take total time of $ t = 9 $ , when he would finally be able to exchange the share number $ 2 $ for the share number $ 3 $ .
In the third example, Bob can never achieve his goal, as the second stock is always strictly more expensive than the first one.