Problem: Example

Input

100 1 0
50 100


Output

14.57738

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


struct Info{
	int x;
	long double h;
};

long double calc(long double tmp_x,long double tmp_distance){
	return sqrt(tmp_x*tmp_x + (tmp_distance/(2*tmp_x))*(tmp_distance/(2*tmp_x)));
}

int main(){

	double distance;
	int N,bounce_limit;

	scanf("%lf %d %d",&distance,&N,&bounce_limit);

	Info info[N];

	for(int i = 0; i < N ;i++){
		cin >> info[i].x >> info[i].h;
	}

	long double tmp_distance;

	long double ans = 1000000.0;
	long double left,right,m,tmp_x,max_x,tmp_y,tmp_dist,tmp_h;

	bool FLG;

	for(int b_count = 1; b_count <= bounce_limit+1; b_count++){

		tmp_distance = (double)distance/b_count;

		left = 0.0,right = DBL_MAX,m = (left+right)/2;

		while(left <= right){

			tmp_x = m;
			tmp_y = tmp_distance/(2*tmp_x);

			FLG = true;

			for(int i = 0; i < N; i++){
				tmp_dist = info[i].x;

				while(tmp_dist >= tmp_distance)tmp_dist -= tmp_distance;

				tmp_h = (tmp_y/tmp_x)*tmp_dist-1.0/(2*tmp_x*tmp_x)*(tmp_dist*tmp_dist);

				if(info[i].h > tmp_h){
					FLG = false;
					break;
				}
			}
			if(FLG){
				left = m+EPS;
			}else{
				max_x = m;
				right = m-EPS;
			}
			m = (left+right)/2;
		}

		ans = min(ans,calc(max_x,tmp_distance));

		left = 0.0,right = max_x;

		while(true){
			if(right-left < EPS){
				ans = min(ans,calc((right-left)/2,tmp_distance));
				break;
			}

			long double mid1 = left + (right-left)/3;
			long double mid2 = left + (right-left)/3*2;

			long double v_1 = calc(mid1,tmp_distance);
			long double v_2 = calc(mid2,tmp_distance);

			ans = min(ans,min(v_1,v_2));

			if(v_1 < v_2){
				right = mid2-EPS;
			}else{
				left = mid1+EPS;
			}
		}
	}

	printf("%.12Lf\n",ans);

	return 0;
}