Problem: Example

Input

100 1 0
50 100


Output

14.57738

Solution (in CPP):

Solution:
#include<bits/stdc++.h>
using namespace std;

const int LOOP=100;

using ld=long double;
const ld EPS=1e-10;
const ld g=1.0;

int main(){
    int n,b;
    ld d;
    cin>>d>>n>>b;
    vector<ld> p(n),h(n);
    for(int i=0;i<n;i++) cin>>p[i]>>h[i];

    ld res=1e10;
    for(int c=1;c<=b+1;c++){
        ld l=d/c;
        vector<ld> px(n);
        for(int i=0;i<n;i++){
            px[i]=p[i]-floor(p[i]/l)*l;
        }
        auto isValidImpl=[&](ld Vx,ld Vy){
            if(isnan(Vx) || isnan(Vy)) return false;
            if(Vx<EPS || Vy<EPS) return false;
            bool res=true;
            for(int i=0;i<n;i++){
                ld t=px[i]/Vx;
                ld y=Vy*t-0.5*g*t*t;
                res = res && (h[i]<y);
            }
            return res;
        };
        auto isValid=[&](ld v){
            ld Y=g*l/2;
            ld X=sqrt(v*v+2*Y);
            ld x0=(X+sqrt(X*X-4*Y))/2;
            ld x1=(X-sqrt(X*X-4*Y))/2;
            return isValidImpl(x0,x1) || isValidImpl(x1,x0);
        };
        ld lb=0,ub=1e10;
        for(int i=0;i<LOOP;i++){
            ld v=(lb+ub)/2;
            if(isValid(v)){
                ub=v;
            }
            else{
                lb=v;
            }
        }
        res=min(res,lb);
    }
    cout<<fixed<<setprecision(10);
    cout<<res<<endl;
    return 0;
}