Problem p00927 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}
template <class T> inline T sqr(T x) { return x * x; }

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i, c)                                                             \\
  for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define exist(s, e) ((s).find(e) != (s).end())
#define range(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) range(i, 0, n)
#define clr(a, b) memset((a), (b), sizeof(a))
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                                               \\
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")"                       \\
       << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi = acos(-1.0);
const ll INF = 1LL << 62;
const int inf = 1 << 29;

int d, n, b;
int p[15];
int h[15];

double y(double x, double vx, double vy) {
  return -(1.0 / 2.0 / vx / vx) * x * x + (vy / vx) * x;
}

double check(const double unit, const double htar) {
  const double vx = sqrt(unit * unit / 8.0 / htar);
  const double vy = unit / 2.0 / vx;
  rep(i, n) {
    double pos = 1.0 * p[i];
    int div = pos / unit;
    pos -= div * unit;
    // dump(pos)
    double height = y(pos, vx, vy);
    // dump(height)

    if (abs(pos) < eps)
      return false;

    if (height < h[i])
      return false;
  }
  return true;
}

int main(void) {

  cin >> d >> n >> b;
  rep(i, n) cin >> p[i] >> h[i];

  double ans = inf;

  rep(i, b + 1) {
    const double unit = 1.0 * d / (i + 1);

    double lb = eps, ub = INF;

    rep(loop, 200) {
      double m = (lb + ub) / 2.0;
      // dump(m)
      if (check(unit, m))
        ub = m;
      else
        lb = m;
    }
    double vx = sqrt(unit * unit / 8.0 / lb);
    double vy = unit / 2.0 / vx;
    ans = min(ans, sqrt(vx * vx + vy * vy));

    const double t = unit / 4.0;
    if (check(unit, t)) {
      double vx = sqrt(unit * unit / 8.0 / t);
      double vy = unit / 2.0 / vx;
      ans = min(ans, sqrt(vx * vx + vy * vy));
    }
  }
  cout.precision(9);
  cout << fixed;
  cout << ans << endl;
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}
template <class T> inline T sqr(T x) { return x * x; }

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i, c)                                                             \\
  for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define exist(s, e) ((s).find(e) != (s).end())
#define range(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) range(i, 0, n)
#define clr(a, b) memset((a), (b), sizeof(a))
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                                               \\
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")"                       \\
       << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi = acos(-1.0);
const ll INF = 1LL << 62;
const int inf = 1 << 29;

int d, n, b;
int p[15];
int h[15];

double y(double x, double vx, double vy) {
  return -(1.0 / 2.0 / vx / vx) * x * x + (vy / vx) * x;
}

double check(const double unit, const double htar) {
  const double vx = sqrt(unit * unit / 8.0 / htar);
  const double vy = unit / 2.0 / vx;
  rep(i, n) {
    double pos = 1.0 * p[i];
    while (pos - unit > eps)
      pos -= unit;
    // dump(pos)
    double height = y(pos, vx, vy);
    // dump(height)
    if (height < h[i])
      return false;
  }
  return true;
}

int main(void) {

  cin >> d >> n >> b;
  rep(i, n) cin >> p[i] >> h[i];

  double ans = inf;

  rep(i, b + 1) {
    const double unit = 1.0 * d / (i + 1);

    double lb = 0.0, ub = 100000.0;

    rep(loop, 200) {
      double m = (lb + ub) / 2.0;
      // dump(m)
      if (check(unit, m))
        ub = m;
      else
        lb = m;
    }
    double vx = sqrt(unit * unit / 8.0 / lb);
    double vy = unit / 2.0 / vx;
    ans = min(ans, sqrt(vx * vx + vy * vy));

    const double t = unit / 4.0;
    if (check(unit, t)) {
      dump(t) double vx = sqrt(unit * unit / 8.0 / t);
      double vy = unit / 2.0 / vx;
      ans = min(ans, sqrt(vx * vx + vy * vy));
    }
  }
  cout.precision(9);
  cout << fixed;
  cout << ans << endl;
  return 0;
}