Problem: Example

Input

100 1 0
50 100


Output

14.57738

Solution (in CPP):

Solution:
#include<stdio.h>
#include<math.h>
#include<algorithm>
using namespace std;
int p[20];
int h[20];
double ABS(double a){return max(a,-a);}
int main(){
	int d,n,b;
	scanf("%d%d%d",&d,&n,&b);
	for(int i=0;i<n;i++){
		scanf("%d%d",p+i,h+i);
	}
	double ret=999999999.9;
	for(int i=1;i<=b+1;i++){
		bool dame=false;
		for(int j=0;j<n;j++)if(i*p[j]%d==0)dame=true;
		if(dame)continue;
		double l=0;
		double r=999999999.9;
		for(int j=0;j<100;j++){
			double m=(l+r)/2;
			bool ok=true;
			for(int k=0;k<n;k++){
				double x=(double)p[k];
				while(x>(double)d/i)x-=(double)d/i;
				double w=ABS((double)d/i/2-x);
				double u=(double)d/i/2;
				double he=m*(1.0-w*w/u/u);
				if(he<(double)h[k])ok=false;
			}
			if(ok)r=m;
			else l=m;
		}
		double L=l;
		double R=999999999.9;
		for(int j=0;j<100;j++){
			double m1=(L*2+R)/3;
			double m2=(L+R*2)/3;
			double vy=sqrt(m1*2);
			double t=vy*2*i;
			double vx=(double)d/t;
			double v1=sqrt(vx*vx+vy*vy);
			ret=min(ret,v1);
			vy=sqrt(m2*2);
			t=vy*2*i;
			vx=(double)d/t;
			double v2=sqrt(vx*vx+vy*vy);
			ret=min(ret,v2);
			if(v1<v2)R=m2;else L=m1;
		}
	}
	printf("%.12f\n",ret);
}