Problem: Example

Input

100 1 0
50 100


Output

14.57738

Solution (in CPP):

Solution:
#include <cmath>
#include <iostream>
#include <iomanip>
using namespace std;

double INF = 2e5;

double dmod(double a, double b) {
    while (a >= b) a -= b;
    return a;
}

double D; int N;
pair<int, int> p[10];

double solve(const int n_bounces) {
    double l = 0, r = INF;

    double itv = D / n_bounces;

    for (int _ = 0; _ < 64; ++_) {
        double v0 = (l + r) / 2.0;
        if (itv > v0 * v0) {
            l = v0;
            continue;
        }

        double theta = (M_PI - asin(itv / v0 / v0))/2;

        double vx = v0 * cos(theta), vy = v0 * sin(theta);

        bool ok = true;
        for (int j = 0; j < N; ++j) {
            double md = dmod(p[j].first, D/n_bounces);
            double height = -(1.0 / 2.0 / vx / vx) * md * md + (vy / vx) * md;
            if (height <= p[j].second) {
                ok = false;
                break;
            }
        }

        (ok ? r : l) = v0;
    }
    return l;
}

int main() {
    int B;
    cin >> D >> N >> B;
    for (int j = 0; j < N; ++j) {
        cin >> p[j].first >> p[j].second;
    }

    double ans = 1e10;
    for (int b = 1; b <= B+1; ++b) {
        ans = min(ans, solve(b));
    }
    cout << setprecision(8) << fixed << ans << endl;

    return 0;
}