Question Description: Simon has given N ratios in the form of A and B that is represented as A/B. 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. Simon 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. Simon's task is to determine the value of R. Constraints: 1 <= N <= 1000 1 <= A <= 1000 |B| <= 1000 1 <= K <= 10^6 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. Simon's answer must contain an absolute or relative error of less than 10^-6.
C Program

#include<stdio.h>
#include<stdlib.h>

double solve(double** arr,double K,int n)
{
    double low = -1e6, high = 1e6;

    // Fix lower bound so B+R > 0 always
    for(int i=0;i<n;i++)
    {
        if(-arr[i][1] > low)
            low = -arr[i][1] + 1e-9;
    }

    for(int it=0; it<100; it++)
    {
        double mid = (low + high) / 2.0;
        double sum = 0;

        for(int i=0;i<n;i++)
            sum += arr[i][0] / (arr[i][1] + mid);

        if(sum > K)
            low = mid;
        else
            high = mid;
    }

    return low;
}

int main()
{
    int n,col;
    scanf("%d %d",&n,&col);

    double **arr = (double**)malloc(n*sizeof(double*));

    for(int i=0;i<n;i++)
    {
        arr[i]=(double*)malloc(2*sizeof(double));
        scanf("%lf %lf",&arr[i][0],&arr[i][1]);
    }

    double K;
    scanf("%lf",&K);

    double R = solve(arr,K,n);

    printf("%.6lf",R);

    return 0;
}