Problem: Example

Input

100 1 0
50 100


Output

14.57738

Solution (in CPP):

Solution:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
#include <map>
#include <climits>
using namespace std;

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define RREP(i,n) for(int i=(int)n-1; i>=0; i--)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();++i)
#define ALL(c) (c).begin(), (c).end()

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<int, pair<int, int> > pipii;
typedef vector<int> vi;

const int INF = 1e9;
const int MOD = 1e9+7;

const double EPS = 1e-9;

bool check(double vix, vector<pair<double, double> > ob, double d){
    for(int i = 0; i < ob.size(); i++){
        double x = ob[i].first;
        double y = ob[i].second;
        while(x > d) x -= d;
        double viy = d / vix / 2;
        double by = -1 * x * x / (2* vix * vix) + viy * x / vix;
        if(by < y - EPS) return true;
    }
    return false;
}

int main(void){
    double d, n, b;
    cin >> d >> n >> b;
    vector<pair<double, double> > ob(n);
	REP(i, n) cin >> ob[i].first >> ob[i].second;
    double ans = 1e9;
    for(int i = 1; i <= b+1; i++){
        double fd = d / i;
        double left = 0.0, right = 1e5;
        while(right - left > EPS){
            double med = (right + left) / 2;
            int f = 0;
            if(check(med, ob, fd)) f = 1;
            if(f) right = med;
            else left = med;
        }
        //cout << "result : " << right << endl;
        left = 0.0;
        while(right - left > EPS){
            double med1 = (right - left) / 3 + left;
            double med2 = (right - left) *2 / 3 + left;
            double y = fd / med1 / 2;
            double ret1 = sqrt(med1 * med1 + y * y);
            y = fd / med2 / 2;
            double ret2 = sqrt(med2 * med2 + y * y);
            if(ret1 > ret2){
                left = med1;
            }
            else right = med2;
            //cout << "left : right " << left << ":" << right << endl;
        }
        double y = fd / right / 2;
        ans = min(ans, sqrt(right * right + y * y));
    }
    printf("%.9f\n", ans);
    return 0;
}