Problem: Example

Input

100 1 0
50 100


Output

14.57738

Solution (in CPP):

Solution:
#include<bits/stdc++.h>
using namespace std;
const double g = 1.0;
const double eps = 1e-8;

double V,X;
vector<double> OX,OY;

double calc(double vy,double t){
  return vy*t-g*t*t/2;
}

int cmp(double lb,double ub,double a){
  return a < lb + eps ? -1 : a > ub - eps ? 1 : 0;
}

bool check(double qx,double qy){
  // vx^2 + vy^2 = V^2 , vx * t = qx, vy * t - 0.5*g*t*t = qy
  double a=g*g/4,b=g*qy-V*V,c=qx*qx+qy*qy;
  double D=b*b-4.0*a*c;
  if(D<0&&D>-eps)D=0;
  if(D<0)return false;
  for(int d=-1;d<=1;d+=2){
    double t2=(-b+d*sqrt(D))/(2*a);
    if(t2<=0)continue;
    double t=sqrt(t2);
    double vx=qx/t,vy=(qy+g*t*t/2.0)/t;
    

    double yt=calc(vy,X/vx);
    if(yt<-eps||eps<yt)continue;
    
    bool flg=true;
    for(int i=0;i<(int)OX.size();i++){
      double ox=OX[i],oy=OY[i];
      double yt=calc(vy,ox/vx);
      if(yt<oy+eps)flg=false;
    }
    if(flg)return true;
  }
  return false;
}


int d,n,b;
double p[10],h[10];
double nd;

bool judge(double m){
  V=m;


  bool flg=check(nd,0);


  for(int i=0;i<n;i++){
    flg|=check(OX[i],OY[i]);
  }
  return flg;
}

void make_table(int B){
  OX.clear();
  OY.clear();
  nd=(double)d/(double)B;

  for(int i=0;i<n;i++){
    double np=p[i];
    while(np>nd)np-=nd;
    OX.push_back(np);
    OY.push_back(h[i]);
  }
}

double solve(){
  double res=1e9;
  for(int I=1;I<=b+1;I++){
    make_table(I);
    double l=0,r=1e9,m;
    for(int i=0;i<100;i++){
      m=(l+r)*0.5;

      //      printf("%.3f %d\n",m,judge(m));
      if(judge(m))r=m;
      else l=m;
    }
    //printf("%d %.8f\n",I,l);
    res=min(res,l);
  }
  return res;
}

int main(){
  cin>>d>>n>>b;
  for(int i=0;i<n;i++)cin>>p[i]>>h[i];
  printf("%.8f\n",solve());
  return 0;
}