Problem: Example

Input

100 1 0
50 100


Output

14.57738

Solution (in CPP):

Solution:
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;


template<typename T>
class Lagrange_polynomial{
private:
    typedef unsigned long ul;
    typedef pair<T,T> point;
    
public:
    vector<point> P;
    
    Lagrange_polynomial(vector<point> P={}):P(P){}
    
    void add_point(point a){P.push_back(a);}
    
    void add_point(vector<point> a){
        for(int i=0;i<a.size();i++){
            P.push_back(a[i]);
        }
    }
    
    T F(T x,const vector<point> &P){
        assert(P.size()>1);
        T ret=0;
        for(ul i=0;i<P.size();i++){
            T a=P[i].S;
            for(ul t=0;t<P.size();t++){
                if(i==t){continue;}
                a*=x-P[t].F;
                assert(P[i].F!=P[t].F);
                a/=P[i].F-P[t].F;
            }
            ret+=a;
        }
        return ret;
    }
    
    bool judge(T x,T y){
        return F(x)==y;
    }
};

double f(double a,double dist){
    ll k=a/dist;
    return a-=dist*k;
}


int main(){
    cout<<fixed<<setprecision(12);
    double d;
    ll n,b;
    cin>>d>>n>>b;
    vector<pd> A(n);
    Lagrange_polynomial<double> L;
    for(int i=0;i<n;i++){
        cin>>A[i].F>>A[i].S;
    }
    double mx=E;
    for(int i=0;i<=b;i++){
        vector<pd> P(3,{0,0});
        double dist=d;
        dist/=i+1;
        P[1]={dist,0};
        pd mi={dist/2,0};
        P[2]=mi;
        for(int t=0;t<n;t++){
            double where=f(A[t].F,dist);
            if(where==0 || where==dist){mi={dist/2,E}; break;}
            if(L.F(where,P)<A[t].S){
                mi={where,A[t].S};
                P[2]=mi;
            }
        }
        if(mi==pd(dist/2,E)){continue;}
        double h=L.F(dist/2,P);
        h=max(h,dist/4);
        //cout<<dist<<" "<<h<<endl;
        mx=min(mx,sqrt(h*2+dist*dist/(h*2)/4));
    }
    cout<<mx<<endl;
    
    return 0;
}