Ratio - TIE BREAKER

2.5

10 votes
Algorithms, Binary Search, Java, Medium, Python
Problem

You are given N ratios in the form of A and B that is represented as AB. The values of A and B are represented as double data type values. The values of B are incorrect. The actual values of B are B+R. You know the actual sum of all the ratios that is available in variable K.

Note: The true values of B, represented as (B+R), are always greater than 0. Your task is to determine the value of R.

Input format

  • First line: Two integers N and col denoting the number of ratios and the value 2 respectively
  • Next N lines: Each line contains two double values A and B
  • Last line: A double value K denoting the sum of all the ratios

Output format

Print the value of R. Your answer must contain an absolute or relative error of less than 106.

Constraints

1N1000

1A1000

|B|1000

1K106

Sample Input
3 2
4 -1
4 0
10 3
5
Sample Output
3.00000000
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

If the value of R is 3.00 then the actual values of B is 2,3,6. Thus, the sum of all ratios =(4/2+4/3+10/6)=5.

Editor Image

?