Problem: Example

Input

100 1 0
50 100


Output

14.57738

Solution (in CPP):

Solution:
#include "bits/stdc++.h"
#include<unordered_map>
#pragma warning(disable:4996)
using namespace std;

double eps(1e-9);

vector<pair<double, double>>obs;

bool check(double jumpdis, double dx,double dy){
	for (int i = 0; i < obs.size(); ++i) {
		double dis = obs[i].first;
		while (dis > jumpdis)dis -= jumpdis;
		if (abs(dis) < eps || abs(dis - jumpdis) < eps)return false;
		double aatime = dis / dx;
		double finy = dy*aatime - aatime*aatime * 1 / 2.0;
		if (finy < obs[i].second)return false;
	}
	return true;
}

int main() {
	double D;
	int  N, B; cin >> D >> N >> B;
	for (int i = 0; i < N; ++i) {
		double p, h; cin >> p >> h;
		obs.push_back(make_pair(p, h));
	}

	double ans = 1e15;

	for (int jumpnum = 1; jumpnum <= B+1; ++jumpnum) {
		double jumpdis = D / jumpnum;

		double mindy = 0.000001;
		double maxdy = 1e9;
		while (mindy < maxdy - 1e-9) {
			const double middy = (mindy + maxdy)/2;
			const double jumptime = middy / 1.0 * 2;
			const double dx = jumpdis / jumptime;
			if (check(jumpdis,dx,middy)) {
				maxdy = middy;
			}
			else {
				mindy = middy;
			}
		}
		{
			const double jumptime = mindy / 1.0 * 2;
			const double dx = jumpdis / jumptime;
			const double nans(sqrt(dx*dx + mindy*mindy));
			int a = 1;
		}
		{
			double nminy = mindy;
			double nmaxy = 1e9;
			while (nminy < nmaxy - 1e-9) {
				const double middy0 = (nminy + 2*nmaxy) / 3;
				const double jumptime0 = middy0 / 1.0 * 2;
				const double dx0 = jumpdis / jumptime0;
				const double midans0 = sqrt(middy0*middy0 + dx0*dx0);
				const double middy1 = (2*nminy + nmaxy) / 3;
				const double jumptime1 = middy1 / 1.0 * 2;
				const double dx1 = jumpdis / jumptime1;
				const double midans1 = sqrt(middy1*middy1 + dx1*dx1);
				if (midans0<midans1) {
					nminy = middy1;
				}
				else {
					nmaxy = middy0;
				}
			}
			mindy = nminy;
		}
		const double jumptime = mindy / 1.0 * 2;
		const double dx = jumpdis / jumptime;
		const double nans(sqrt(dx*dx + mindy*mindy));
		ans = min(nans, ans);
	}
	cout <<fixed<<setprecision(22)<< ans << endl;
	return 0;
}