Luck is a fundamental part of betting. Some people improve their chances and earnings by having good knowledge of what they are betting on. We will take a different approach.
Various bookmakers offer different odds or quotas for the same outcome. (An odds of means that if you bet euro and predict the outcome correctly, you get euros back. If you predict the outcome incorrectly, you of course get nothing back. Note that you pay euro regardless of the outcome.) What if you could be certain of making a profit by cleverly placing several bets? You would want to make this guaranteed profit as large as possible.
The event we want to bet on has two possible outcomes. There are bookmakers that offer different odds. Let us denote the odds offered by the -th bookmaker for the first outcome with , and the odds offered for the second outcome with . You can place a bet on any subset of the offered odds. You can even bet on both outcomes at the same bookmaker. However, all bets have to be exactly euro and you cannot bet on the same outcome with the same bookmaker multiple times.
In case of the first outcome, you will receive euros from every bookmaker with whom you placed a bet on the first outcome. Similarly, in case of the second outcome, you will receive euros from all eligible bookmakers. Of course in both cases, you already paid euro for every bet you placed.
What is the largest guaranteed profit (i.e. regardless of the outcome) if you place your bets optimally?
Input
The first line contains the number of bookmakers, . The following lines describe the odds offered by each bookmaker with two space-separated real numbers and – the odds for the first and second outcome offered by the -th bookmaker. The odds will be given to at most 4 decimal places.
Constraints
Subtask 1 (20%)
Subtask 2 (40%)
Subtask 3 (40%)
- no additional constraints
Output
Output the maximum guaranteed profit rounded to exactly 4 decimal places.
Sample Input
4
1.4 3.7
1.2 2
1.6 1.4
1.9 1.5
Sample Output
0.5000
Explanation
The optimal betting strategy consists of betting on the second outcome with the first bookmaker and on the first outcome with the third and fourth bookmaker. In case of the first outcome, we will earn and in case of the second outcome . So we're guaranteed euros regardless of the outcome.
Comments