题目描述
Problem Description
At the annual pig slaughter event, butcher Bajs is conducting the final stage of the event—distributing a portion of his award-winning ham to everyone present.
This year, there are $n$ participants in the event, with the $i$-th person having already eaten $a_i$ kilograms of ham. Bajs distributes his ham according to the ratio $b_1:b_2:\cdots:b_n$. In other words, let $S=\sum\limits_{j=1}^n b_j$, then the $i$-th person will receive $\dfrac{b_i}{S}$ of the total ham weight.
However, Bajs has not yet determined the total amount of ham he will distribute, because after distributing and eating the ham, a ranking list will be created based on the amount of ham each person has eaten, sorted from most to least (if two people have eaten the same amount, they will be sorted by their numbers in ascending order), and the annual person of the event, the top of the ranking list, will be announced. Although Bajs has been bribed by others multiple times, he still refuses to change the distribution ratio and claims to be honest and kind-hearted. Bajs is a severe obsessive-compulsive disorder sufferer, so he wants the ranking list to have the numbers in the order $1, 2, \cdots, n$. Please help Bajs determine the total amount of ham he needs to distribute to meet his requirements.
Input Format
The first line contains an integer $n$, representing the number of participants in the pig slaughter event.
The following $n$ lines each contain two integers $a_i$ and $b_i$, representing the amount of ham the $i$-th person has already eaten and their share in the ham distribution, respectively (as described in the problem statement).
Output Format
If it is impossible for Bajs to meet the requirements regardless of how much ham he distributes, output -1.
Otherwise, output a real number $x$, representing the amount of ham in kilograms that Bajs will distribute. You need to ensure:
- $0 \leqslant x \leqslant 10^7$.
- $x$ should have no more than $12$ decimal places. It is recommended to round the answer before outputting.
If any of the above conditions are not met, it will be judged as WA.
If there are multiple solutions, output any one of them. That is, you do not need to ensure the minimum amount of ham Bajs distributes.
Sample Input and Output
Sample Input #1
3
7 1
3 2
10 0
Sample Output #1
10.5
Sample Input #2
3
2 1
4 0
0 3
Sample Output #2
-1
Sample Input #3
5
15 4
6 7
12 5
9 6
1 7
Sample Output #3
87
Notes
[Sample 1 Explanation]
Bajs distributes $10.5$ kilograms of ham, and since the distribution ratio is $1:2:0$, the three people receive $3.5$ kilograms, $7$ kilograms, and $0$ kilograms of ham respectively. In the end, they have eaten a total of $10.5$ kilograms, $10$ kilograms, and $10$ kilograms of ham respectively. This meets Bajs's requirements.
[Data Range and Constraints]
For all data, $2 \leqslant n \leqslant 1000$, $0 \leqslant a_i, b_i \leqslant 10^6$.
[Problem Source]
This problem is from COCI 2013-2014 CONTEST 3 T4 KOLINJE, configured according to the original problem data, with a full score of $120$ points.
Translated and provided by Eason_AC.
Feedback on the problem checker is welcome.
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分