Problem: Example

Input

100 1 0
50 100


Output

14.57738

Solution (in CPP):

Solution:
#include <bits/stdc++.h>

using namespace std;

int d, n, b;
double x[16], y[16];

bool ok(double v, double wid, int dnum)
{
    double vx, vy;
    
    double b = sqrt(v * v + wid), c = wid / 2;
    
    if (b * b - 4 * c < 0) return (false);
    
    vx = (b + sqrt(b * b - 4 * c)) / 2, vy = (b - sqrt(b * b - 4 * c)) / 2;
    
    double myx[16], myy[16];
    bool ok = true;
    
    for (int i = 0; i < n; i++){
        myx[i] = x[i];
        myy[i] = y[i];
    }
    for (int i = 0; i < dnum; i++){
        for (int j = 0; j < n; j++){
            if (0 <= myx[j] && myx[j] <= wid){
                if (-(1.0 / (2 * vx * vx)) * myx[j] * myx[j] + vy / vx * myx[j] < myy[j]) ok = false;
            }
            myx[j] -= wid;
        }
    }
    if (ok) return (true);
    
    swap(vx, vy);
    
    for (int i = 0; i < n; i++){
        myx[i] = x[i];
        myy[i] = y[i];
    }
    for (int i = 0; i < dnum; i++){
        for (int j = 0; j < n; j++){
            if (0 <= myx[j] && myx[j] <= wid){
                if (-(1.0 / (2 * vx * vx)) * myx[j] * myx[j] + vy / vx * myx[j] < myy[j]) return (false);
            }
            myx[j] -= wid;
        }
    }
    
    return (true);
}

int main()
{
    scanf("%d %d %d", &d, &n, &b);
    
    for (int i = 0; i < n; i++){
        scanf("%lf %lf", x + i, y + i);
    }
    
    double ans = 1e30;
    for (int i = 0; i <= b; i++){
        double l = 1e-10, r = 1e5, mid;
        double width = d * 1.0 / (i + 1);
        for (int j = 0; j <= 1000; j++){
            mid = (l + r) / 2;
            if (ok(mid, width, i + 1)){
                r = mid;
            }
            else l = mid;
        }
        ans = min(ans, mid);
    }
    
    printf("%.10f\n", ans);
    
    return (0);
}