Problem: Example

Input

100 1 0
50 100


Output

14.57738

Solution (in CPP):

Solution:
// Template {{{
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
using namespace std;
typedef long long LL;

#ifdef LOCAL
#include "contest.h"
#else
#define dump(x) 
#endif

class range {
    struct Iterator {
        int val, inc;
        int operator*() {return val;}
        bool operator!=(Iterator& rhs) {return val < rhs.val;}
        void operator++() {val += inc;}
    };
    Iterator i, n;
    public:
    range(int e) : i({0, 1}), n({e, 1}) {}
    range(int b, int e) : i({b, 1}), n({e, 1}) {}
    range(int b, int e, int inc) : i({b, inc}), n({e, inc}) {}
    Iterator& begin() {return i;}
    Iterator& end() {return n;}
};

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
inline bool valid(int x, int w) { return 0 <= x && x < w; }

void iostream_init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.setf(ios::fixed);
    cout.precision(12);
}
//}}}

int main(){
    iostream_init();
    int N, B;
    double D;
    while(cin >> D >> N >> B) {
        vector<double> P(N);
        vector<double> H(N);
        REP(i, N) cin >> P[i] >> H[i];

        double ans = 1e16;

        for(int b = 0; b <= B; b++) {
            double p = D / (b+1);
            double lb = M_PI / 4;
            double ub = M_PI / 2;
            double v = 0;
            REP(_, 60) {
                double th = (lb+ub) / 2;
                double vx = sqrt(p / 2.0 / tan(th));

                v = vx/cos(th); // update

                bool ok = true;
                REP(i, N) {
                    double x = P[i] - int(P[i] / p) * p;
                    double y = -(0.5/vx/vx)*x*x + tan(th)*x;
                    if(y < H[i]) ok = false;
                }
                if(ok) {
                    ub = th;
                } else {
                    lb = th;
                }
            }

            ans = min(ans, v);
        }
        cout << ans << endl;
    }

    return 0;
}

/* vim:set foldmethod=marker: */