Problem: Example

Input

100 1 0
50 100


Output

14.57738

Solution (in CPP):

Solution:
#include<bits/stdc++.h>
#define double long double
#define N 10
using namespace std;
typedef pair<bool,double> P;

const double EPS = 1e-12;

double d, n, b, p[N], h[N];

P check(double s, double A, int cnt){
  
  double l = 0, r = 1000000000;
  
  while(l+EPS<r){
    
    double m = (l + r) / 2.0;
    double vx = m * cos(s);
    double vy = m * sin(s);
    double x = vx * 2 * vy;
    
    if(x<A) l=m;
    else r=m;

  }
  
  double vx = l * cos(s);
  double vy = l * sin(s);
  
  bool res = true;
  
  double x=0;
  
  for(int i=0;i<=cnt;i++){
    
    for(int j=0;j<n;j++)
      
      if(x-EPS<p[j]&&p[j]<x+A+EPS){
	
	if(abs(p[j]-x)<EPS||abs(p[j]-x)<EPS) res=false;
	
	double X=abs(p[j]-x);
	
	if(-X*X/(2*vx*vx)+X*vy/vx<=h[j]+EPS) res=false;
      }
    
    x+=A;
  }
  
  return P(res, l);
}

double sim(int cnt){
  
  double A=1.0*d/(cnt+1);
  
  double l = M_PI/4.0, r = M_PI/2.0;
  
  while(l+EPS<r){
    
    double m = (l + r) / 2.0;
    
    if(!check(m,A,cnt).first) l = m;
    else r=m;
  }
  
  return check(l,A,cnt).second;
}

int main(){
  
  cin>>d>>n>>b;

  for(int i=0;i<n;i++) cin>>p[i]>>h[i];
  
  double ans=(1e9);
  
  for(int i=0;i<=b;i++) ans=min(ans, sim(i));
  
  printf("%.8Lf\n", ans);
    
  return 0;
}