Problem: Example

Input

100 1 0
50 100


Output

14.57738

Solution (in CPP):

Solution:
#include <cmath>
#include <cstdio>
#include <iostream>
using namespace std;
int main(){
  int d, n, b;
  cin >> d >> n >> b;
  int p[n], h[n];
  for(int i = 0; i < n; ++i){
    cin >> p[i] >> h[i];
  }
  double INF = 1E15, ans = INF;
  for(int i = 0; i <= b; ++i){
    double m = (double)d/(i+1)/2.0, p_, g = 1.0, t = 0.0;
    //cout << "m = " << m << endl;
    for(int j = 0; j < n; ++j){
      p_ = p[j];
      while(p_-2*m >= 0.0){
        p_ -= 2*m;
      }
      if(p_ > 1.0/INF){
        double a = h[j]/(m*m - (p_-m)*(p_-m));
        //cout << "a = " << a << endl;
        t = max(t,2*a*m);
      }else{
        t = INF;
        break;
      }
    }
    //cout << "t = " << t << endl;
    if(t < 1){
      //cout << "sqrt(2*m*g) = " << sqrt(2*m*g) << endl;
      ans = min(ans, sqrt(2*m*g));
    }else{
      //cout << "sqrt(m*g*(t+1.0/t)) = " << sqrt(m*g*(t+1.0/t)) << endl;
      ans = min(ans, sqrt(m*g*(t+1.0/t)));
    }
  }
  printf("%.12f\n",ans);
  return 0;
}