Problem: Example

Input

100 1 0
50 100


Output

14.57738

Solution (in CPP):

Solution:
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;

const double kInf = 1e10;
const double kEps = 1e-8;
const double kPi = 2 * acos(0);
const int kItr = 100;

int N, B;
double D, P[10], H[10];

void read();
void solve();

bool is_ok(double, double);

inline bool flt(double a, double b) { return a + kEps < b; }

int main() {
  cout.setf(ios::fixed), cout.precision(5);
  read();
  solve();
  return 0;
}

void read() {
  cin >> D >> N >> B, ++B;
  for (int i = 0; i < N; ++i)
    cin >> P[i] >> H[i];
}

void solve() {
  double res = kInf;

  for (int i = 1; i <= B; ++i) {
    double low, up, mid;

    low = kPi / 4, up = kPi / 2;
    for (int itr = 0; itr < kItr; ++itr) {
      mid = (low + up) / 2;
      if (is_ok(mid, D / i))
        up = mid;
      else
        low = mid;
    }

    res = min(res, sqrt((D / i) / sin(2 * low)));
  }

  cout << res << "\n";
}

bool is_ok(double tht, double l) {
  double v = sqrt(l / sin(2 * tht)), vx = v * cos(tht), vy = v * sin(tht), x, y;

  for (int i = 0; i < N; ++i) {
    x = fmod(P[i], l);
    y = vy * x / vx - x * x / (2 * vx * vx);
    if (flt(y, H[i]))
      return false;
  }

  return true;
}