Problem: Example

Input

100 1 0
50 100


Output

14.57738

Solution (in CPP):

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

struct Info{
	int x;
	double h;
};

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

int main(){

	double dist;
	int N,B;

	scanf("%lf %d %d",&dist,&N,&B);

	Info info[N];

	for(int i = 0; i < N ;i++)scanf("%d %lf",&info[i].x,&info[i].h);

	double  tmp_dist;

	double  ans = 1000000.0;
	double  left,right,m,tmp_x,max_x,tmp_y,diff_dist,tmp_h,limit,maximize_x;

	bool FLG;

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

		tmp_dist = (double)dist/b_count;

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

		while(left <= right){

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

			FLG = true;

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

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

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

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

		limit = tmp_dist*tmp_dist/4.0;

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

		while(left <= right){
			if(m*m*m*m > limit){
				right = m-EPS;
			}else{
				maximize_x = m;
				left = m+EPS;
			}
			m = (left+right)/2;
		}

		if(max_x >= maximize_x){
			ans = min(ans,calc(maximize_x,tmp_dist));
		}else{
			ans = min(ans,calc(max_x,tmp_dist));
		}
	}

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

	return 0;
}