Problem: Example

Input

100 1 0
50 100


Output

14.57738

Solution (in CPP):

Solution:
#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <cassert>
using namespace std;
#define double long double
const double PI = acos(-1);
double d, l;
int n, b;
double p[10];
double h[10];

bool check(double Vx, double Vy, int pass) {
	for(int i = 0; i < n; i++) {
		if(i == pass) continue;
		double x = p[i] - l * (int)(p[i] / l);
		double y = -(1.0 / (2 * Vx * Vx)) * x * x + (Vy / Vx) * x;
		if(y < h[i]) return false;
	}
	return true;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	while(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++) {
			l = d / (i + 1);
			double V = sqrt(l / 2);
			if(check(V, V, -1)) {
				ans = min(ans, V * sqrt(2));
			}
			for(int j = 0; j < n; j++) {
				double x = p[j] - l * (int)(p[j] / l);
				double y = h[j];
				double Vx = sqrt((l - x) * x / (2 * y));
				double Vy = l / (2 * Vx);
				//cout << Vx << " " << Vy << endl;
				//cout << -(x * x / (2 * Vx * Vx)) + Vy * x / Vx << endl;;
				if(check(Vx, Vy, j)) {
					ans = min(ans, sqrt(Vx * Vx + Vy * Vy));
				}
			}
		}

		cout << setprecision(15) << ans << endl;
	}
}