Problem: Example

Input

100 1 0
50 100


Output

14.57738

Solution (in CPP):

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

#define rep(i, j) for(int i=0; i < (int)(j); i++)
#define repeat(i, j, k) for(int i = (j); i < (int)(k); i++)
#define all(v) v.begin(),v.end()
#define debug(x) cerr << #x << " : " << x << endl

template<class T> bool set_min(T &a, const T &b) { return a > b  ? a = b, true : false; }

using ld = long double;

const ld INF = 1e9;
const ld EPS = 1e-9;
const ld G = 1.0;

int main() {
    ld D;
    int N, B; cin >> D >> N >> B;    
    B += 1;
    vector<ld> P(N), H(N); rep(i, N) cin >> P[i] >> H[i];
    
    ld ans = INF * INF;
    repeat(b, 1, B + 1) {
        ld d = D / b;
        
        auto calc_vx = [&] (ld vy) {
            return d * G / 2.0 / vy;
        };
        auto calc_v = [&] (ld vy) {
            ld vx = calc_vx(vy);
            return sqrt(vx * vx + vy * vy);
        };
        auto calc_y = [&] (ld vy, ld x) {
            ld vx = calc_vx(vy);
            return -(G / 2.0 / vx / vx) * x * x + vy / vx * x;
        };
        auto can_reach = [&] (ld vy) {
            rep(i, N) {
                int idx = P[i] / d;
                ld sx = d * idx;
                if(calc_y(vy, P[i] - sx) < H[i]) return false;
            }
            return true;
        };

        {
            ld vv = sqrt(d * G / 2.0);
            if(can_reach(vv)) ans = calc_v(vv);
        }
        rep(i, N) {
            int idx = P[i] / d;
            ld sx = d * idx;
            ld x = P[i] - sx;
            ld y = H[i];
            ld l = 0,  r = INF;
            while(r - l > EPS) {
                ld vy = (l + r) / 2.0;
                (calc_y(vy, x) >= y ? r : l) = vy;
            }
            if(can_reach(r)) {
                set_min(ans, calc_v(r));
            }
        }
    }
    printf("%.16f\n", (double)ans);
    return 0;
}