Problem: Example

Input

100 1 0
50 100


Output

14.57738

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;

constexpr double INF = 1e9;
constexpr double eps = 1e-8;

int main() {
    double d;
    int n, b;
    cin >> d >> n >> b;
    vector<double> p(n), h(n);
    for(int i=0; i<n; ++i) {
        cin >> p[i] >> h[i];
    }
    double res = INF;
    for(int i=0; i<=b; ++i) {
        double interval = d / (i+1);
        bool neg = false;
        for(int j=0; j<=i; ++j) {
            for(int i=0; i<n; ++i) {
                neg |= abs(interval * j - p[i]) < eps;
            }
        }
        if(neg) {
            continue;
        }
        vector<double> vx, vy;
        vx.push_back(sqrt(interval / 2));
        vy.push_back(vx.back());
        for(int j=0; j<=i; ++j) {
            double now = interval * j;
            for(int k=0; k<n; ++k) {
                double pp = p[k] - now;
                if(0 < pp && pp < interval) {
                    vx.push_back(sqrt(1 / (2*h[k]) * pp * (interval - pp)));
                    vy.push_back(interval / (2 * vx.back()));
                }
            }
        }
        for(int j=0; j<vx.size(); ++j) {
            bool ok = true;
            for(int k=0; k<=i; ++k) {
                double now = interval * k;
                for(int l=0; l<n; ++l) {
                    double pp = p[l] - now;
                    if(0 < pp && pp < interval) {
                        double t = pp / vx[j];
                        double hh = vy[j] * t - 0.5 * t*t;
                        ok &= (hh - h[l]) >= -eps;
                    }
                }
            }
            if(ok) {
                res = min(res, hypot(vx[j], vy[j]));
            }
        }
    }
    cout << fixed << setprecision(10) << res << endl;
}