#P8244. [COCI 2013/2014 #3] KOLINJE
[COCI 2013/2014 #3] KOLINJE
Problem Description
At the annual pig slaughter festival, butcher Bajs is doing the final part of the event: taking out part of his award-winning ham and distributing it to everyone attending.
This year, there are participants. The -th person has already eaten kilograms of ham. Bajs will distribute his ham in the ratio . In other words, let , then the -th person will receive of the total ham weight.
However, Bajs still cannot decide the total amount of ham to take out, because after everyone receives and eats their share, a ranking list will be made according to how many kilograms of ham each person has eaten, from large to small (if two people have eaten the same amount, they are ordered by increasing index), and the first place will be announced as the person of the year. Although Bajs has been bribed many times, he still refuses to change the distribution ratio, saying that he is honest and kind. Bajs has severe OCD, so he wants the indices on the ranking list, from top to bottom, to be exactly . Please help Bajs determine the total amount of ham he should take out to satisfy this requirement.
Input Format
The first line contains an integer , the number of participants.
Then follow lines, each containing two integers , representing the kilograms of ham already eaten by the -th person and the weight ratio they take in the distribution (see the Description).
Output Format
If no matter how much ham Bajs takes out the requirement cannot be satisfied, output -1.
Otherwise, output a real number , the number of kilograms of ham Bajs takes out. You must ensure:
- .
- has at most digits after the decimal point. It is recommended to round your answer before output.
If at least one of the above conditions is not satisfied, your answer will be judged as WA.
If there are multiple solutions, output any one of them. That is, you do not need to minimize the amount of ham Bajs takes out.
3
7 1
3 2
10 0
10.5
3
2 1
4 0
0 3
-1
5
15 4
6 7
12 5
9 6
1 7
87
Hint
[Sample 1 Explanation]
Bajs took out kilograms of ham. Since the distribution ratio is , the three people receive kilograms, kilograms, and kilograms of ham respectively. In the end, they have eaten a total of kilograms, kilograms, and kilograms of ham respectively. This satisfies Bajs's requirement.
[Constraints]
For all testdata, , .
[Source]
This problem is from COCI 2013-2014 CONTEST 3 T4 KOLINJE. With the original test configuration, the full score is points.
Translated and整理 (zhengli) by Eason_AC.
Suggestions for improving the checker of this problem are welcome.
Translated by ChatGPT 5