Problem:
F: Mountain View
Mr. Mt. is eager to take photos of mountains all over the world. Today, Mr. Mt. visits one of the most interesting mountain ranges, the
Alps of Curved Mountains. The shape of all the mountains of the Alps of Curved Mountains is, surprisingly, hemisphere.
Mr. Mt. just decided the place from where he will take photos of the mountains. The area covering the mountains is flat, horizontal
ground, and the place he chose is far enough from the mountains. Hence the mountains look like two-dimensional semicircles in a row,
where all the straight segments of the semicircles are aligned with a straight line. Some of them may be overlapped or completely
covered by other semicircles.
Mr. Mt. is waiting for the sunset. After sunset, the mountains should be in shadow and cannot be distinguished. In that situation, Mr. Mt.
is interested in how the photos will look like. You, his camera assistant, are also a great programmer. Given the coordinates and radiuses
of all the semicircles, he asks you to write a program to calculate the heights of the 2D shadow at the positions he wants to know.
Figure F-1 illustrates the mountains of Sample 2. The first, second, third mountains are overlapped, and the fifth mountain is covered by
the fourth mountain. Figure F-2 shows the mountains in shadow. For example, at position 82, there are the fourth and fifth mountains,
and the shadow's height is the highest of them, the height of the fourth mountain.
Figure F-1. Mountains of Sample 2
Figure F-2. Mountains in shadow and positions of Sample 2
Input
The input consists of a single test case in the format below.
$N$
$c_1$ $r_1$
:
$c_N$ $r_N$
$Q$
$x_1$
:
$x_Q$
The first line contains a single integer $N$ ($1 \leq N \leq 10^5$), where $N$ is the number of mountains of the Alps of Curved Mountains. The $i$-th of the following $N$ lines contains two integers $c_i$ ($1 \leq c_i \leq 10^8$) and $r_i$ ($1 \leq r_i \leq 10^8$). $c_i$ is the position of the center of the $i$-th semicircle in a straight line, where "center" means the center of the circle made by reflecting the semicircle on the straight segment of the semicircle. $r_i$ is the radius of the $i$-th semicircle. The following line contains a single integer $Q$ ($1 \leq Q \leq 10^5$), where $Q$ is the number
of the positions on a straight line Mr. Mt. is interested in. The $j$-th of the following $Q$ lines contains a single integer $x_j$ ($1 \leq x_j \leq 10^8$),
where $x_j$ is the $j$-th position on a straight line Mr. Mt. is interested in.
Output
Output $Q$ lines, the $j$-th of which is the height of the shadow of the mountains at the $j$-th position Mr. Mt. is interested in. Absolute or
relative errors less than $10^{-7}$ are permissible.
Examples
Input 1
3
1 10
4 10
10 5
6
4
2
8
12
14
18
Output 1
10.0000000000
9.9498743711
9.1651513899
6.0000000000
3.0000000000
0.0000000000
Input 2
5
23 10
32 7
41 10
75 12
79 6
6
10
32
36
60
75
82
Output 2
0.0000000000
7.0000000000
8.6602540378
0.0000000000
12.0000000000
9.7
...(truncated)

Submitted solutions:

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define loop(i,m, n) for (ll i = m; i <= n; ++i)
#define vl vector<ll>
#define vvl vector<vl>
#define inf 1000000000000000000LL
#define eps 0.000000001

//2つの円の交点
struct point {
	double x,y;
};
pair<point,point>pif={{inf,inf},{inf,inf}};
pair<point, point> circle_cross(point p1, double r1,point p2, double r2){
    double dx = p2.x - p1.x;
    double dy = p2.y - p1.y;
    double d = hypot(abs(dx),abs(dy)); // 2点間の距離

    // 交点なし：離れすぎ or 完全に内側
    if (d > r1 + r2 + eps || d + eps < abs(r1 - r2)) {
        return pif;
    }

    // 円が同一（無限に交わる）：対応が必要な場合記述
    if (d < eps && abs(r1 - r2) < eps) {}

    // 交点の中点とp1の距離
    double a = (r1*r1 - r2*r2 + d*d) / (2*d);
	
	// 交点の中点と交点の距離
    double h = sqrt(max(0.0, r1*r1 - a*a));

	//交点の中点
    double xm = p1.x + a * dx / d;
    double ym = p1.y + a * dy / d;

    // 円の中心同士の線分に対する、長さhの垂直線の変化量
    double hx = -dy * (h / d);
    double hy = dx * (h / d);

    double x3 = xm + hx;
    double y3 = ym + hy;
    double x4 = xm - hx;
    double y4 = ym - hy;

    return {{x3, y3}, {x4, y4}};
}


int main(){
    ll n;
	cin>>n;
	vector<pair<ll,ll>> cr;
	
	//入力読み取って円を左端でソート
	rep(i,n){
		ll rr,cc;
		cin>>cc>>rr;
		cc-=rr;
		rr*=-1;
		cr.push_back({cc,rr});
	}
	sort(cr.begin(),cr.end());
	rep(i,n){
		cr[i].second*=-1;
		cr[i].first+=cr[i].second;
	}

	map<double,ll> mp;
	mp[cr[0].first-cr[0].second]=0;
	loop(i,1,n-1){
		while(1){
			ll now=mp.rbegin()->second;
			ll right=cr[now].first+cr[now].second;
			ll left=cr[i].first-cr[i].second;
			
			//重なりがない場合
			if(right<=left){
				mp[left]=i;
				break;
			}

			ll left2=cr[now].first-cr[now].second;
			//左端で重なってる場合
			if(left==left2)break;


			//交点を求める
			point p1={(double)cr[now].first,0};
			double r1=cr[now].second;
			point p2={(double)cr[i].first,0};
			double r2=cr[i].second;
			pair<point,point> tmp=circle_cross(p1,r1,p2,r2);

			//包含されてる場合
			if(tmp.first.x==pif.first.x)break;

			//交点が既にある区間を消去する場合
			if(mp.rbegin()->first>tmp.first.x){
				mp.erase(mp.rbegin()->first);
				continue;
			}

			mp[tmp.first.x]=i;
			break;
		}
	}

	ll q;
	cin>>q;
	cout<<fixed<<setprecision(15);
	while(q--){
		//最寄りの円
		ll x;
		cin>>x;
		auto it=mp.upper_bound(x);
		it--;
		ll i=it->second;
		ll tmp=cr[i].second*cr[i].second-(x-cr[i].first)*(x-cr[i].first);
		if(tmp<=0)cout<<0.0<<endl;
		else cout<<sqrt(tmp)<<endl;
	}
	
    return 0;
}
accuracy: 1
time_ms: 250
memory_kb: 11016
final_rank: 8

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define loop(i,m, n) for (ll i = m; i <= n; ++i)
#define vl vector<ll>
#define vvl vector<vl>
#define inf 1000000000000000000LL
#define eps 0.000000001

//2つの円の交点
struct point {
	double x,y;
};
pair<point,point>pif={{inf,inf},{inf,inf}};
pair<point, point> circle_cross(point p1, double r1,point p2, double r2){
    double dx = p2.x - p1.x;
    double dy = p2.y - p1.y;
    double d = hypot(abs(dx),abs(dy)); // 2点間の距離

    // 交点なし：離れすぎ or 完全に内側
    if (d > r1 + r2 + eps || d + eps < abs(r1 - r2)) {
        return pif;
    }

    // 円が同一（無限に交わる）：対応が必要な場合記述
    if (d < eps && abs(r1 - r2) < eps) {}

    // 交点の中点とp1の距離
    double a = (r1*r1 - r2*r2 + d*d) / (2*d);
	
	// 交点の中点と交点の距離
    double h = sqrt(max(0.0, r1*r1 - a*a));

	//交点の中点
    double xm = p1.x + a * dx / d;
    double ym = p1.y + a * dy / d;

    // 円の中心同士の線分に対する、長さhの垂直線の変化量
    double hx = -dy * (h / d);
    double hy = dx * (h / d);

    double x3 = xm + hx;
    double y3 = ym + hy;
    double x4 = xm - hx;
    double y4 = ym - hy;

    return {{x3, y3}, {x4, y4}};
}


int main(){
    ll n;
	cin>>n;
	vector<pair<ll,ll>> cr;
	
	//入力読み取って円を左端でソート
	rep(i,n){
		ll rr,cc;
		cin>>cc>>rr;
		cc-=rr;
		rr*=-1;
		cr.push_back({cc,rr});
	}
	sort(cr.begin(),cr.end());
	rep(i,n){
		cr[i].second*=-1;
		cr[i].first+=cr[i].second;
	}

	map<double,ll> mp;
	mp[cr[0].first-cr[0].second]=0;
	loop(i,1,n-1){
		ll now=mp.rbegin()->second;
		ll right=cr[now].first+cr[now].second;
		ll left=cr[i].first-cr[i].second;
		
		//重なりがない場合
		if(right<=left){
			mp[left]=i;
			continue;
		}

		ll left2=cr[now].first-cr[now].second;
		//左端で重なってる場合
		if(left==left2)continue;


		//交点を求める
		point p1={(double)cr[now].first,0};
		double r1=cr[now].second;
		point p2={(double)cr[i].first,0};
		double r2=cr[i].second;
		pair<point,point> tmp=circle_cross(p1,r1,p2,r2);

		//包含されてる場合
		if(tmp.first.x==pif.first.x)continue;

		mp[tmp.first.x]=i;
	}

	ll q;
	cin>>q;
	cout<<fixed<<setprecision(15);
	while(q--){
		//最寄りの円
		ll x;
		cin>>x;
		auto it=mp.upper_bound(x);
		it--;
		ll i=it->second;
		ll tmp=cr[i].second*cr[i].second-(x-cr[i].first)*(x-cr[i].first);
		if(tmp<=0)cout<<0.0<<endl;
		else cout<<sqrt(tmp)<<endl;
	}
	
    return 0;
}
accuracy: 0.14814814814814814
time_ms: 120
memory_kb: 5584
final_rank: 17

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll, ll>
template<bool isMin = true> struct CHT {
#define x first
#define y second
    CHT() = default;
    deque<pll> v;
    bool empty(){return v.empty();}
    void clear(){return v.clear();}
    inline int sgn(ll x){return !x?0:(x<0?-1:1);}
    using D = long double;
    inline bool check(const pll& a, const pll& b, const pll& c){
        if(b.y == a.y or c.y == b.y) return sgn(b.x - a.x) * sgn(c.y - b.y) >= sgn(c.x - b.x) * sgn(b.y - a.y);
        return D(b.x - a.x) * sgn(c.y - b.y) / D(abs(b.y - a.y)) >= D(c.x - b.x) * sgn(b.y - a.y) / D(abs(c.y - b.y));
    }
    void add(ll a, ll b){
        if (!isMin) a *= -1, b *= -1;
        pll line(a, b);
        if (empty()) v.emplace_front(line);
        else {
            if (ll c = v[0].x; c <= a){
                if(c == a){
                    if (v[0].y <= b) return;
                    v.pop_front();
                }
                while(v.size() >= 2 and check(line, v[0], v[1]))v.pop_front();
                v.emplace_front(line);
            } else {
                assert(a <= v.back().x);
                if(v.back().x == a){
                    if(v.back().y <= b) return;
                    v.pop_back();
                }
                while (v.size() >= 2 and check(v[v.size() - 2], v.back(), line)) v.pop_back();
                v.emplace_back(line);
            }
        }
    }
    ll get_y(const pll&a, const ll& x) {return a.x * x + a.y;}
    ll query(ll x){
        assert(!empty());
        while (v.size() >= 2 and get_y(v[0], x) >= get_y(v[1], x)) v.pop_front();
        return get_y(v[0], x) * (isMin ? 1 : -1);
    }
#undef x
#undef y
};
int main(){
    cin.tie(0)->sync_with_stdio(0), cout.tie(0);
    int N;
    cin >> N;
    CHT<false> C;
    vector<pair<ll, ll>> CR(N);
    for (int i = 0; i < N; i++){
        long long c, r;
        cin >> c >> r;
        CR[i] = {c, r};
    }
    sort(CR.begin(), CR.end());
    for (auto [c, r] : CR){
        C.add(2 * c, r * r - c * c);
    }
    int Q;
    cin >> Q;
    vector<pair<ll, ll>> P(Q);
    for (int i = 0; i < Q; i++){
        int x;
        cin >> x;
        P[i] = {x, i};
    }
    sort(P.begin(), P.end());
    vector<double> ans(Q);
    for (auto [x, i] : P){
        ans[i] = max(0.0, sqrt(C.query(x) - x * x));
    }
    for (int i = 0; i < Q; i++){
        printf("%.20f\n", ans[i]);
    }

}
accuracy: 1
time_ms: 60
memory_kb: 9216
final_rank: 2

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll, ll>
template<bool isMin = true> struct CHT {
#define x first
#define y second
    CHT() = default;
    deque<pll> v;
    bool empty(){return v.empty();}
    void clear(){return v.clear();}
    inline int sgn(ll x){return !x?0:(x<0?-1:1);}
    using D = long double;
    inline bool check(const pll& a, const pll& b, const pll& c){
        if(b.y == a.y or c.y == b.y) return sgn(b.x - a.x) * sgn(c.y - b.y) >= sgn(c.x - b.x) * sgn(b.y - a.y);
        return D(b.x - a.x) * sgn(c.y - b.y) / D(abs(b.y - a.y)) >= D(c.x - b.x) * sgn(b.y - a.y) / D(abs(c.y - b.y));
    }
    void add(ll a, ll b){
        if (!isMin) a *= -1, b *= -1;
        pll line(a, b);
        if (empty()) v.emplace_front(line);
        else {
            if (ll c = v[0].x; c <= a){
                if(c == a){
                    if (v[0].y <= b) return;
                    v.pop_front();
                }
                while(v.size() >= 2 and check(line, v[0], v[1]))v.pop_front();
                v.emplace_front(line);
            } else {
                assert(a <= v.back().x);
                if(v.back().x == a){
                    if(v.back().y <= b) return;
                    v.pop_back();
                }
                while (v.size() >= 2 and check(v[v.size() - 2], v.back(), line)) v.pop_back();
                v.emplace_back(line);
            }
        }
    }
    ll get_y(const pll&a, const ll& x) {return a.x * x + a.y;}
    ll query(ll x){
        assert(!empty());
        while (v.size() >= 2 and get_y(v[0], x) >= get_y(v[1], x)) v.pop_front();
        return get_y(v[0], x) * (isMin ? 1 : -1);
    }
#undef x
#undef y
};
int main(){
    cin.tie(0)->sync_with_stdio(0), cout.tie(0);
    int N;
    cin >> N;
    CHT<false> C;
    vector<pair<ll, ll>> CR(N);
    for (int i = 0; i < N; i++){
        long long c, r;
        cin >> c >> r;
        CR[i] = {c, r};
    }
    sort(CR.begin(), CR.end());
    for (auto [c, r] : CR){
        C.add(2 * c, r * r - c * c);
    }
    int Q;
    cin >> Q;
    vector<pair<int, int>> P(Q);
    for (int i = 0; i < Q; i++){
        int x;
        cin >> x;
        P[i] = {x, i};
    }
    sort(P.begin(), P.end());
    vector<double> ans(Q);
    for (auto [x, i] : P){
        ans[i] = max(0.0, sqrt(C.query(x) - x * x));
    }
    for (int i = 0; i < Q; i++){
        printf("%.20f\n", ans[i]);
    }

}
accuracy: 0.1111111111111111
time_ms: 50
memory_kb: 6784
final_rank: 20

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll, ll>
template<bool isMin = true> struct CHT {
#define x first
#define y second
    CHT() = default;
    deque<pll> v;
    bool empty(){return v.empty();}
    void clear(){return v.clear();}
    inline int sgn(ll x){return !x?0:(x<0?-1:1);}
    using D = long double;
    inline bool check(const pll& a, const pll& b, const pll& c){
        if(b.y == a.y or c.y == b.y) return sgn(b.x - a.x) * sgn(c.y - b.y) >= sgn(c.x - b.x) * sgn(b.y - a.y);
        return D(b.x - a.x) * sgn(c.y - b.y) / D(abs(b.y - a.y)) >= D(c.x - b.x) * sgn(b.y - a.y) / D(abs(c.y - b.y));
    }
    void add(ll a, ll b){
        if (!isMin) a *= -1, b *= -1;
        pll line(a, b);
        if (empty()) v.emplace_front(line);
        else {
            if (ll c = v[0].x; c <= a){
                if(c == a){
                    if (v[0].y <= b) return;
                    v.pop_front();
                }
                while(v.size() >= 2 and check(line, v[0], v[1]))v.pop_front();
                v.emplace_front(line);
            } else {
                assert(a <= v.back().x);
                if(v.back().x == a){
                    if(v.back().y <= b) return;
                    v.pop_back();
                }
                while (v.size() >= 2 and check(v[v.size() - 2], v.back(), line)) v.pop_back();
                v.emplace_back(line);
            }
        }
    }
    ll get_y(const pll&a, const ll& x) {return a.x * x + a.y;}
    ll query(ll x){
        assert(!empty());
        while (v.size() >= 2 and get_y(v[0], x) >= get_y(v[1], x)) v.pop_front();
        return get_y(v[0], x) * (isMin ? 1 : -1);
    }
#undef x
#undef y
};
int main(){
    cin.tie(0)->sync_with_stdio(0), cout.tie(0);
    int N;
    cin >> N;
    CHT<false> C;
    vector<pair<int, int>> CR(N);
    for (int i = 0; i < N; i++){
        long long c, r;
        cin >> c >> r;
        CR[i] = {c, r};
    }
    sort(CR.begin(), CR.end());
    for (auto [c, r] : CR){
        C.add(2 * c, r * r - c * c);
    }
    int Q;
    cin >> Q;
    vector<pair<int, int>> P(Q);
    for (int i = 0; i < Q; i++){
        int x;
        cin >> x;
        P[i] = {x, i};
    }
    sort(P.begin(), P.end());
    vector<double> ans(Q);
    for (auto [x, i] : P){
        ans[i] = max(0.0, sqrt(C.query(x) - x * x));
    }
    for (int i = 0; i < Q; i++){
        printf("%.20f\n", ans[i]);
    }

}
accuracy: 0.1111111111111111
time_ms: 50
memory_kb: 6016
final_rank: 18

code_snippet: //
// Created by 井桁広翔 on 24/12/19.
//
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0; i < (ll)(n); i++)
#define rrep(i, s, e) for(ll i=s; i>= (ll)(e); i--)
#define repn(i, e) for (ll i=0; i <= (ll)(e); i++)
#define reps(i, s,e) for(ll i=s; i < (ll)(e); i++ )
#define repsn(i,s,e) for(ll i=s; i<=(ll)(e); i++)
#define each(p,a) for(auto &p: a)
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef pair<ll, ll> pll;
typedef vector<pair<ll,ll>> vpll;
typedef pair<ll,ll> pll;
typedef vector<pair<ll, ll>> vpll;
typedef tuple<ll, ll, ll> tpl3;
#define all(a) (a).begin(), (a).end()
#define sz(x) (ll)x.size()
template<class T> bool chmin(T& a, T b) { if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) { if (a < b) {a =b; return true;} return false;}
vector<ll> _ta = {0,0,1,-1,1,1,-1,1};
vector<ll> _yo = {1,-1,0,0,1,-1,1,-1};
bool isin(ll i, ll j, ll h, ll w) {return (0 <= i && i < h && 0 <= j && j < w);}
ll INF = 1LL << 60;

using  ld = long double;
ld EPS = 1e-9;
int sgn(ld a) {
  if (a < -EPS) {
    return -1;
  }else if (a > EPS) {
    return 1;
  }else {
    return 0;
  }
}

ld crosspoint(ld clen,ld r1,ld r2) {
  // if (sgn(clen) == 0) {
  //   return 0;
  // }
  return ((r1*r1)-(r2*r2)+(clen*clen))/(2*(clen));
}
int main() {
  ll n;cin >> n;
  vector<pll>cr(n);
  rep(i,n) {
    ll c,r;cin >> c >> r;
    cr[i] = {c,r};
  }
  auto cp =[&](pll a,pll b) {
    auto [ac,ar] = a;
    auto [bc,br] = b;
    if (ac-ar != bc - br) {
      return ac-ar < bc - br;
    }else {
      return ar > br;
    }
  };
  sort(all(cr),cp);
  vector<tuple<ld,ld,ll>> lri;
  //前操作
  rep(i,n) {
    auto [c,r] = cr[i];
    if (lri.empty()) {
      lri.push_back({c-r,c+r,i});
      continue;
    }
    while (true) {
      //今の一番うしろと繋げられるか,更に前に戻るか
      auto [lf,lb,lid] = lri.back();
      if (sgn((ld)c-r - lb) >= 0) { //後ろにある
        lri.emplace_back(c-r,c+r,i);
        break;
      }
      //内包
      if (sgn(lb - (c+r)) >= 0) {
        break;
      }
      if (c-r == cr[lid].first -cr[lid].second) {
        //左端が一致もいらない
        break;
      }
      ld d = (ld)cr[lid].first + crosspoint(c-cr[lid].first,cr[lid].second,r);
      if (sgn(lf - d) >= 0) {
        lri.pop_back();
      }else {
        lri.pop_back();
        lri.emplace_back(lf,d,lid);
        lri.emplace_back(d,c+r,i);
        break;
      }
    }



  }
  // each(p,lri) {
  //   auto [l,r,i] = p;
  //   cout  << l << " " << r << " " << i << endl;
  // }

  ll q;cin >> q;
  while (q--) {
    ll x;cin >> x;
    ll id = lower_bound(all(lri),tuple<ld,ld,ll>{x,INF,INF})-lri.begin();
    id--;
    if (id <0) {
      cout << 0 << endl;
      continue;
    }else {
      auto [l,r,i] = lri[id];
      if (sgn((ld)x-l) >= 0 && sgn(r-(ld)x) >= 0) {
        ld C = cr[i].first;
        ld R = cr[i].second;
        ld ans  = sqrt(R*R-(C-x)*(C-x));
        cout << fixed << setprecision(10) << ans << endl;
      }else {
        cout << 0 << endl;
      }
    }
  }
  return 0;
}
accuracy: 1
time_ms: 210
memory_kb: 12648
final_rank: 7

code_snippet: #include <bits/stdc++.h>

using namespace std;

const int INF = 1e9;

struct Circle {
    long long x, r;
};

long double intersection(Circle &c1, Circle &c2) {
    return (long double)(c1.r * c1.r - c2.r * c2.r - c1.x * c1.x + c2.x * c2.x) / (2 * (c2.x - c1.x));
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(20);
    int n;
    cin >> n;
    vector<Circle> arr(n);
    for (auto &el : arr)
        cin >> el.x >> el.r;
    sort(arr.begin(), arr.end(), [](const Circle &a, const Circle &b) {
        auto al = a.x - a.r, bl = b.x - b.r;
        if (al != bl)
            return al < bl;
        auto ar = a.x + a.r, br = b.x + b.r;
        return ar > br;
    });
    vector<Circle> good = {arr[0]};
    vector<long double> inters;
    for (int i = 1; i < n; ++i) {
        auto &c = arr[i];
        if (c.x + c.r <= good.back().x + good.back().r)
            continue;
        while (!inters.empty() && c.x - c.r <= good.back().x + good.back().r) {
            long double x = intersection(good.back(), c);
            if (x > inters.back())
                break;
            good.pop_back();
            inters.pop_back();
        }
        inters.push_back(intersection(good.back(), c));
        good.push_back(c);
    }
    int q;
    cin >> q;
    for (int qi = 0; qi < q; ++qi) {
        long long x;
        cin >> x;
        int i = lower_bound(inters.begin(), inters.end(), x) - inters.begin();
        auto &c = good[i];
        long double ans = 0;
        if (c.x - c.r <= x && x <= c.x + c.r)
            ans = sqrtl(c.r * c.r - x * x - c.x * c.x + 2 * x * c.x);
        cout << ans << '\n';
    }
}
accuracy: 1
time_ms: 120
memory_kb: 7992
final_rank: 3

code_snippet: #include <bits/stdc++.h>

using namespace std;

const int INF = 1e9;

struct Circle {
    long long x, r;
};

long double intersection(Circle &c1, Circle &c2) {
    return (long double)(c1.r * c1.r - c2.r * c2.r - c1.x * c1.x + c2.x * c2.x) / (2 * (c2.x - c1.x));
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
    int n;
    cin >> n;
    vector<Circle> arr(n);
    for (auto &el : arr)
        cin >> el.x >> el.r;
    sort(arr.begin(), arr.end(), [](const Circle &a, const Circle &b) {
        auto al = a.x - a.r, bl = b.x - b.r;
        if (al != bl)
            return al < bl;
        auto ar = a.x + a.r, br = b.x + b.r;
        return ar > br;
    });
    int maxr = arr[0].x + arr[0].r;
    vector<Circle> good = {arr[0]};
    vector<long double> inters;
    for (int i = 1; i < n; ++i) {
        auto &c = arr[i];
        if (c.x + c.r <= maxr)
            continue;
        while (!inters.empty() && c.x - c.r <= good.back().x + good.back().r) {
            long double x = intersection(good.back(), c);
            if (x > inters.back())
                break;
            good.pop_back();
            inters.pop_back();
        }
        if (good.back().x + good.back().r <= c.x - c.r)
            inters.push_back(c.x - c.r);
        else
            inters.push_back(intersection(good.back(), c));
        good.push_back(c);
        maxr = c.x + c.r;
    }
    auto kek = inters;
    sort(kek.begin(), kek.end());
    assert(kek == inters);
    int q;
    cin >> q;
    for (int qi = 0; qi < q; ++qi) {
        long long x;
        cin >> x;
        int i = lower_bound(inters.begin(), inters.end(), x) - inters.begin();
        auto &c = good[i];
        long double ans = 0;
        if (c.x - c.r <= x && x <= c.x + c.r)
            ans = sqrtl(c.r * c.r - x * x - c.x * c.x + 2 * x * c.x);
        cout << ans << '\n';
    }
}
accuracy: 1
time_ms: 110
memory_kb: 9712
final_rank: 4

code_snippet: #include <bits/stdc++.h>

using namespace std;

const int INF = 1e9;

struct Circle {
    long long x, r;
};

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(20);
    int n;
    cin >> n;
    vector<Circle> arr(n);
    for (auto &el : arr)
        cin >> el.x >> el.r;
    sort(arr.begin(), arr.end(), [](const Circle &a, const Circle &b) {
        auto al = a.x - a.r, bl = b.x - b.r;
        if (al != bl)
            return al < bl;
        auto ar = a.x + a.r, br = b.x + b.r;
        return ar > br;
    });
    int maxr = -INF;
    vector<Circle> good;
    for (auto &c : arr) {
        if (c.x + c.r <= maxr)
            continue;
        good.push_back(c);
        maxr = c.x + c.r;
    }
    vector<long double> inters(good.size() - 1);
    for (int i = 0; i < good.size() - 1; ++i) {
        auto &c1 = good[i];
        auto &c2 = good[i + 1];
        inters[i] = (long double)(c1.r * c1.r - c2.r * c2.r - c1.x * c1.x + c2.x * c2.x) / (2 * (c2.x - c1.x));
    }
    int q;
    cin >> q;
    for (int qi = 0; qi < q; ++qi) {
        long long x;
        cin >> x;
        int i = lower_bound(inters.begin(), inters.end(), x) - inters.begin();
        auto &c = good[i];
        long double ans = 0;
        if (c.x - c.r <= x && x <= c.x + c.r)
            ans = sqrtl(c.r * c.r - x * x - c.x * c.x + 2 * x * c.x);
        cout << ans << '\n';
    }
}
accuracy: 0.14814814814814814
time_ms: 100
memory_kb: 4492
final_rank: 16

code_snippet: #include <bits/stdc++.h>

using namespace std;

const int INF = 1e9;

struct Circle {
    long long x, r;
};

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(20);
    int n;
    cin >> n;
    vector<Circle> arr(n);
    for (auto &el : arr)
        cin >> el.x >> el.r;
    sort(arr.begin(), arr.end(), [](const Circle &a, const Circle &b) {
        auto al = a.x - a.r, bl = b.x - b.r;
        if (al != bl)
            return al < bl;
        auto ar = a.x + a.r, br = b.x + b.r;
        return ar > br;
    });
    int maxr = -INF;
    vector<Circle> good;
    for (auto &c : arr) {
        if (c.x + c.r <= maxr)
            continue;
        good.push_back(c);
        maxr = c.x + c.r;
    }
    vector<long double> inters(good.size() - 1);
    for (int i = 0; i < good.size() - 1; ++i) {
        auto &c1 = good[i];
        auto &c2 = good[i + 1];
        inters[i] = (long double)(c1.r * c1.r - c2.r * c2.r - c1.x * c1.x + c2.x * c2.x) / (2 * (c2.x - c1.x));
    }
    int q;
    cin >> q;
    for (int qi = 0; qi < q; ++qi) {
        int x;
        cin >> x;
        int i = lower_bound(inters.begin(), inters.end(), x) - inters.begin();
        auto &c = good[i];
        long double ans = 0;
        if (c.x - c.r <= x && x <= c.x + c.r)
            ans = sqrtl(c.r * c.r - x * x - c.x * c.x + 2 * x * c.x);
        cout << ans << '\n';
    }
}
accuracy: 0.1111111111111111
time_ms: 90
memory_kb: 4384
final_rank: 19

code_snippet: #include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rrep(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define ALL(v) (v).begin(), (v).end()
#define UNIQUE(v) sort(ALL(v)), (v).erase(unique(ALL(v)), (v).end())
#define SZ(v) (int)v.size()
#define MIN(v) *min_element(ALL(v))
#define MAX(v) *max_element(ALL(v))
#define LB(v, x) int(lower_bound(ALL(v), (x)) - (v).begin())
#define UB(v, x) int(upper_bound(ALL(v), (x)) - (v).begin())

using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long;
using i128 = __int128_t;
using u128 = __uint128_t;
const int inf = 0x3fffffff;
const ll INF = 0x1fffffffffffffff;

template <typename T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T, typename U> T ceil(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? (x + y - 1) / y : x / y);
}
template <typename T, typename U> T floor(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? x / y : (x - y + 1) / y);
}
template <typename T> int popcnt(T x) {
    return __builtin_popcountll(x);
}
template <typename T> int topbit(T x) {
    return (x == 0 ? -1 : 63 - __builtin_clzll(x));
}
template <typename T> int lowbit(T x) {
    return (x == 0 ? -1 : __builtin_ctzll(x));
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "P(" << p.first << ", " << p.second << ")";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &map_var) {
    os << "{";
    for (auto itr = map_var.begin(); itr != map_var.end(); itr++) {
        os << "(" << itr->first << ", " << itr->second << ")";
        itr++;
        if (itr != map_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &set_var) {
    os << "{";
    for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
        os << *itr;
        ++itr;
        if (itr != set_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
#ifdef LOCAL
#define show(...) _show(0, #__VA_ARGS__, __VA_ARGS__)
#else
#define show(...) true
#endif
template <typename T> void _show(int i, T name) {
    cerr << '\n';
}
template <typename T1, typename T2, typename... T3>
void _show(int i, const T1 &a, const T2 &b, const T3 &...c) {
    for (; a[i] != ',' && a[i] != '\0'; i++)
        cerr << a[i];
    cerr << ":" << b << " ";
    _show(i + 1, a, c...);
}

/**
 * @brief template
 */

double Cross(double C1, double R1, double C2, double R2) {
    return ((R1*R1-R2*R2)/(C2-C1)+C1+C2)/2.0;
}

int main() {
    int N;
    cin >> N;
    vector<double> C(N), R(N);
    rep(i,0,N) cin >> C[i] >> R[i];
    vector<int> ord(N);
    iota(ALL(ord),0);
    sort(ALL(ord),[&](int i, int j){return (C[i]-R[i]==C[j]-R[j] ? R[i]>R[j] : C[i]-R[i] < C[j]-R[j]);});
    vector<double> X;
    vector<int> Y;
    X.push_back(-inf);
    for (int i : ord) {
        if (X.back() <= C[i]-R[i]) {
            X.push_back(C[i]-R[i]);
            X.push_back(C[i]+R[i]);
            Y.push_back(-1);
            Y.push_back(i);
        }
        else if (C[i]+R[i] <= X.back()) {
            continue;
        }
        else {
            X.pop_back();
            while(1) {
                double Z = Cross(C[Y.back()],R[Y.back()],C[i],R[i]);
                if (Z <= X.back()) {
                    X.pop_back();
                    Y.pop_back();
                }
                else {
                    X.push_back(Z);
                    Y.push_back(i);
                    break;
                }
            }
            X.push_back(C[i]+R[i]);
        }
    }
    Y.push_back(-1);
    int Q;
    cin >> Q;
    while(Q--) {
        double Z;
        cin >> Z;
        int ID = UB(X,Z);
        ID--;
        if (Y[ID] == -1) cout << 0 << endl;
        else {
            printf("%.12f\n", sqrt(R[Y[ID]]*R[Y[ID]]-(Z-C[Y[ID]])*(Z-C[Y[ID]])));
        }
    }
}
accuracy: 1
time_ms: 240
memory_kb: 8460
final_rank: 6

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define rep(i, m, n) for (auto i = (m); i < (n); i++)
#define rept(i, n) rep(i, 0, n)
#define repr(i, m, n) for (auto i = (m); i-- > (n);)
#define reptr(i, n) repr(i, 0, n)
#define all(x) begin(x), end(x)
#define sz(x) (int)size(x)
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vc = vector<char>;
using pii = pair<int, int>;

constexpr int MaxN = 100005;
int n;
int c[MaxN], r[MaxN];
int k[MaxN], z[MaxN], m;
int ix[MaxN];

int calc_z(int j, int i) {
	if (c[j]+r[j] <= c[i]-r[i]) return c[i]-r[i];
	int lo = c[j]-r[j], hi = c[i]+r[i];
	while (hi - lo > 1) {
		int mid = (lo + hi) / 2;
		ll h_j = 1LL * r[j] * r[j] - 1LL * (c[j]-mid) * (c[j]-mid);
		ll h_i = 1LL * r[i] * r[i] - 1LL * (c[i]-mid) * (c[i]-mid);
		(h_j <= h_i ? hi : lo) = mid;
	}
	return hi;
}

void solve() {
	scanf("%d", &n);
	rept(i, n) scanf("%d%d", &c[i], &r[i]);
	iota(ix, ix+n, 0);
	sort(ix, ix+n, [](int i, int j) {
		return c[i] < c[j];
	});
	rept(t, n) {
		int i = ix[t];
		bool covered = false;
		int zm = c[i] - r[i];
		while (m) {
			int j = k[m-1];
			if (c[i]-r[i] <= c[j]-r[j]) {
				m--;
				continue;
			}
			if (c[i]+r[i] <= c[j]+r[j]) {
				covered = true;
				break;
			}
			zm = calc_z(j, i);
			if (zm <= z[m-1]) {
				m--;
				continue;
			} else {
				break;
			}
		}
		if (!covered) k[m] = i, z[m] = zm, m++;
	}
	int q; scanf("%d", &q);
	while (q--) {
		int x; scanf("%d", &x);
		if (x <= z[0]) {
			printf("0\n");
			continue;
		}
		int ix = upper_bound(z, z+m, x) - z - 1;
		int i = k[ix];
		double ans = sqrt(max(0LL, 1LL * r[i] * r[i] - 1LL * (c[i]-x) * (c[i]-x)));
		printf("%.9f\n", ans);
	}
}

int main() {
	int n = 1;
	// scanf("%d", &n);
	while (n--) solve();
}
accuracy: 1
time_ms: 90
memory_kb: 5472
final_rank: 1

code_snippet: #line 2 "cp-library/src/cp-template.hpp"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull  = unsigned long long;
using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;
using i128 = __int128_t;
template < class T > bool chmin(T& a, T b) { if(a > b) { a = b; return true; } return false; }
template < class T > bool chmax(T& a, T b) { if(a < b) { a = b; return true; } return false; }
template < class T, class U > T ceil (T x, U y) { return (x > 0 ? (x + y - 1) / y :           x / y); }
template < class T, class U > T floor(T x, U y) { return (x > 0 ?           x / y : (x - y + 1) / y); }
int popcnt(i32 x) { return __builtin_popcount(x); }
int popcnt(u32 x) { return __builtin_popcount(x); }
int popcnt(i64 x) { return __builtin_popcountll(x); }
int popcnt(u64 x) { return __builtin_popcountll(x); }

#line 2 "cp-library/src/utility/rep_itr.hpp"
template < class T > struct itr_rep {
    T i, d;
    constexpr itr_rep(const T i) noexcept : i(i), d(1) {}
    constexpr itr_rep(const T i, const T d) noexcept : i(i), d(d) {}
    void operator++() noexcept { i += d; }
    constexpr int operator*() const noexcept { return i; }
    constexpr bool operator!=(const itr_rep x) const noexcept { return d > 0 ? i < x.i : i > x.i; }
};

template < class T > struct rep {
    const itr_rep< T > s, t;
    constexpr rep(const T t) noexcept : s(0), t(t) {}
    constexpr rep(const T s, const T t) noexcept : s(s), t(t) {}
    constexpr rep(const T s, const T t, const T d) noexcept : s(s, d), t(t, d) {}
    constexpr auto begin() const noexcept { return s; }
    constexpr auto end  () const noexcept { return t; }
};

template < class T > struct revrep {
    const itr_rep < T > s, t;
    constexpr revrep(const T t) noexcept : s(t - 1, -1), t(-1, -1) {}
    constexpr revrep(const T s, const T t) noexcept : s(t - 1, -1), t(s - 1, -1) {}
    constexpr revrep(const T s, const T t, const T d) noexcept : s(t - 1, -d), t(s - 1, -d) {}
    constexpr auto begin() const noexcept { return s; }
    constexpr auto end  () const noexcept { return t; }
};
#line 3 "cp-library/src/utility/io.hpp"

/* 128bit integer */
istream& operator>>(istream& is, i128& x) {
    std::string s; is >> s;
    int pm = (s[0] == '-');
    x = 0;
    for(int i : rep(pm, int(s.size()))) x = x * 10 + (s[i] - '0');
    if(pm) x *= -1;
    return is;
}
ostream& operator<<(ostream& os, const i128& x) {
    if(x == 0) return os << '0';
    i128 y = x;
    if(y < 0) { os << '-'; y *= -1; }
    std::vector<int> ny;
    while(y > 0) { ny.push_back(y % 10); y /= 10; }
    for(int i : revrep(ny.size())) os << ny[i];
    return os;
}

template < class S, class T > istream& operator>>(istream& is,       std::pair< S, T >& x) { is >> x.first        >> x.second; return is; }
template < class S, class T > ostream& operator<<(ostream& os, const std::pair< S, T >& x) { os << x.first << " " << x.second; return os; }

namespace scanner {
    struct sca {
        template < class T > operator T() {
            T s; std::cin >> s; return s;
        }
    };
    struct vec {
        int n;
        vec(int n) : n(n) {}
        template < class T > operator std::vector< T >() {
            std::vector< T > v(n);
            for(T& x : v) std::cin >> x;
            return v;
        }
    };
    struct mat {
        int h, w;
        mat(int h, int w) : h(h), w(w) {}
        template < class T > operator std::vector< std::vector< T > >() {
            std::vector m(h, std::vector< T >(w));
            for(std::vector< T >& v : m) for(T& x : v) std::cin >> x;
            return m;
        }
    };
    struct speedup {
        speedup() {
            std::cin.tie(0);
            std::ios::sync_with_stdio(0);
        }
    } speedup_instance;
}
scanner::sca in() { return scanner::sca(); }
scanner::vec in(int n) { return scanner::vec(n); }
scanner::mat in(int h, int w) { return scanner::mat(h, w); }

namespace printer {
    void precision(int d) { std::cout << std::fixed << std::setprecision(d); }
    void flush() { std::cout.flush(); }
}

template < class T >
ostream& operator<<(ostream& os, const std::vector< T > a) {
    int n = a.size();
    for(int i : rep(n)) { os << a[i]; if(i != n - 1) os << ' '; }
    return os;
}

int print() { std::cout << '\n'; return 0; }
template < class head, class... tail > int print(head&& h, tail&&... t) {
    std::cout << h; if(sizeof...(tail)) std::cout << ' ';
    return print(std::forward<tail>(t)...);
}
template < class T > int print_n(const std::vector< T > a) {
    int n = a.size();
    for(int i : rep(n)) std::cout << a[i] << "\n";
    return 0;
}


#line 2 "cp-library/src/utility/key_val.hpp"

template < class K, class V >
struct key_val {
    K key; V val;
    key_val() {}
    key_val(K key, V val) : key(key), val(val) {}
    template < std::size_t Index >
    std::tuple_element_t< Index, key_val >& get() {
        if constexpr (Index == 0) return key;
        if constexpr (Index == 1) return val;
    }
};

namespace std {

template < class K, class V > struct tuple_size < key_val< K, V > > : integral_constant< size_t, 2 > {};
template < class K, class V > struct tuple_element < 0, key_val< K, V > > { using type = K; };
template < class K, class V > struct tuple_element < 1, key_val< K, V > > { using type = V; };

}
#line 2 "cp-library/src/utility/vec_op.hpp"
template < class T > key_val< int, T > max_of(const vector< T >& a) {
    int i = std::max_element(a.begin(), a.end()) - a.begin();
    return {i, a[i]};
}
template < class T > key_val< int, T > min_of(const vector< T >& a) {
    int i = std::min_element(a.begin(), a.end()) - a.begin();
    return {i, a[i]};
}
template < class S, class T > S sum_of(const vector< T >& a) {
    S sum = 0;
    for(const T x : a) sum += x;
    return sum;
}
template < class S, class T > vector< S > freq_of(const vector< T >& a, T L, T R) {
    vector< S > res(R - L, S(0));
    for(const T x : a) res[x - L] += 1;
    return res;
}
template < class S, class T > struct prefix_sum {
    vector< S > s;
    prefix_sum(const vector< T >& a) : s(a) {
        s.insert(s.begin(), S(0));
        for(int i : rep(a.size())) s[i + 1] += s[i];
    }
    // [L, R)
    S sum(int L, int R) { return s[R] - s[L]; }
};
#line 3 "cp-library/src/utility/heap.hpp"

template < class T > using heap_min = std::priority_queue< T, std::vector< T >, std::greater< T > >;
template < class T > using heap_max = std::priority_queue< T, std::vector< T >, std::less< T > >;

#line 27 "cp-library/src/cp-template.hpp"

#line 1 "cp-library/src/algorithm/bin_search.hpp"
template < class T, class F >
T bin_search(T ok, T ng, F f) {
    while(abs(ng - ok) > 1) {
        T mid = (ok + ng) / 2;
        (f(mid) ? ok : ng) = mid;
    }
    return ok;
}

template < class T, class F >
T bin_search_real(T ok, T ng, F f, int step = 80) {
    while(step--) {
        T mid = (ok + ng) / 2;
        (f(mid) ? ok : ng) = mid;
    }
    return ok;
}
#line 2 "cp-library/src/algorithm/argsort.hpp"

template < class T > std::vector< int > argsort(const std::vector< T > &a) {
    std::vector< int > ids((int)a.size());
    std::iota(ids.begin(), ids.end(), 0);
    std::sort(ids.begin(), ids.end(), [&](int i, int j) {
        return a[i] < a[j] || (a[i] == a[j] && i < j);
    });
    return ids;
}
#line 1 "macro.hpp"
namespace macro {

using size_type = int;
template < class container > void  sort(container& a) { std::sort(std:: begin(a), std:: end(a)); }
template < class container > void rsort(container& a) { std::sort(std::rbegin(a), std::rend(a)); }
template < class container > void reverse(container& a) { std::reverse(std::begin(a), std::end(a)); }
template < class container > void unique(container& a) {
    std::sort(std::begin(a), std::end(a));
    a.erase(std::unique(std::begin(a), std::end(a)), std::end(a));
}
template < class container > container  sorted(const container& a) { container b = a;  sort(b); return std::move(b); }
template < class container > container rsorted(const container& a) { container b = a; rsort(b); return std::move(b); }
template < class container, class compare > void sort(container& a, const compare& cmp) { std::sort(std::begin(a), std::end(a), cmp); }
template < class container, class compare > container sorted(const container& a, const compare& cmp) { container b = a; sort(b, cmp); return std::move(b); }
template < class container, class value > size_type lower_bound(const container& a, const value& x) { return std::lower_bound(std::begin(a), std::end(a), x) - std::begin(a); }
template < class container, class value > size_type upper_bound(const container& a, const value& x) { return std::upper_bound(std::begin(a), std::end(a), x) - std::begin(a); }

const std::vector<std::pair<size_type, size_type>> dir4 = { {+1,  0}, {-1,  0}, { 0, +1}, { 0, -1} };
const std::vector<std::pair<size_type, size_type>> dir8 = { {-1, -1}, {-1,  0}, {-1, +1}, { 0, -1}, { 0, +1}, {+1, -1}, {+1,  0}, {+1, +1} };

#ifdef _DEBUG
#define debug(x) std::cout << "[" << __LINE__ << "] " << #x << ": " << x << std::endl
#else
#define debug(x)
#endif

template < class container > void concat(container& a, const container& b) {
    a.insert(std::end(a), std::begin(b), std::end(b));
}
std::vector<size_type> iota(const size_type n) {
    std::vector<size_type> I(n);
    std::iota(std::begin(I), std::end(I), 0);
    return I;
}
template < class container > std::vector<size_type> sort_idx(const container& a) {
    const size_type n = a.size();
    std::vector<size_type> I = iota(n);
    std::sort(std::begin(I), std::end(I), [&](size_type i, size_type j) { return a[i] < a[j] or (a[i] == a[j] and i < j); });
    return I;
}
template < class container, class compare > std::vector<size_type> sort_idx(const container& a, const compare& cmp) {
    const size_type n = a.size();
    std::vector<size_type> I = iota(n);
    std::sort(std::begin(I), std::end(I), [&](size_type i, size_type j) { return cmp(a[i], a[j]) or (a[i] == a[j] and i < j); });
    return std::move(I);
}

struct grid {
    using size_type = int;
    size_type H, W;
    grid(const size_type H, const size_type W) : H(H), W(W) {}
    bool contains(const size_type i, const size_type j) {
        return 0 <= i and i < H and 0 <= j and j < W;
    }
};

using f64 = long double;

template < class T > vector< T >& operator++(vector< T >& a) { for(T& x : a) x++; return a; }
template < class T > vector< T >& operator--(vector< T >& a) { for(T& x : a) x--; return a; }
template < class T > vector< T >  operator++(vector< T >& a, signed) { vector< T > res = a; for(T& x : a) x++; return res; }
template < class T > vector< T >  operator--(vector< T >& a, signed) { vector< T > res = a; for(T& x : a) x--; return res; }

} // namespace macro

using namespace macro;
#line 1 "cp-library/src/data_structure/cht_offline_get_min.hpp"
template < class T > class CHT_offline_get_min {
  private:
    struct Line {
        T a, b;
        Line(T a, T b) : a(a), b(b) {}
        T eval(T x) { return a * x + b; }
    };

    T sgn;
    int n;
    vector< Line > ls;
    vector< T > xs;

  public:
    T inf = numeric_limits< T >::max();

    CHT_offline_get_min(vector< T > &x, bool is_min = true) : xs(x) {
        sort(xs.begin(), xs.end());
        xs.erase(unique(xs.begin(), xs.end()), xs.end());
        n = xs.size();
        ls.assign(n << 1, Line(0, inf));
        sgn = is_min ? +1 : -1;
    }

    void add_line(T a, T b) { update(a, b, 0, n); }

    void add_segment(T a, T b, T l, T r) {
        int xl = distance(xs.begin(), lower_bound(xs.begin(), xs.end(), l));
        int xr = distance(xs.begin(), lower_bound(xs.begin(), xs.end(), r));
        update(a, b, xl, xr);
    }

    T query(T x) {
        int i = distance(xs.begin(), lower_bound(xs.begin(), xs.end(), x));
        assert(i != n && x == xs[i]);
        T v = inf;
        for(i += n; i > 0; i >>= 1) v = min(v, ls[i].eval(x));
        return sgn * v;
    }

  private:
    void update(T a, T b, int l, int r) {
        a *= sgn, b *= sgn;
        Line f(a, b);
        for(l += n, r += n; l < r; l >>= 1, r >>= 1) {
            if(l & 1) descend(f, l++);
            if(r & 1) descend(f, --r);
        }
    }

    void descend(Line g, int i) {
        int l = i, r = i + 1;
        while(l < n) l <<= 1, r <<= 1;
        while(l < r) {
            int m = (l + r) >> 1;
            T xl = xs[l - n], xm = xs[m - n], xr = xs[r - 1 - n];
            Line &f = ls[i];
            if(f.eval(xl) <= g.eval(xl) && f.eval(xr) <= g.eval(xr)) return;
            if(f.eval(xl) >= g.eval(xl) && f.eval(xr) >= g.eval(xr)) { f = g; return; }
            if(f.eval(xm) >  g.eval(xm)) swap(f, g);
            if(f.eval(xl) >  g.eval(xl)) i = i << 1 | 0, r = m; else i = i << 1 | 1, l = m;
        }
    }
};
#line 4 "A.cpp"

int main() {
    int N = in();
    vector<pair<f64,f64>> C(N);
    for(auto &[c, r] : C) c = in(), r = in();
    int Q = in();
    vector<f64> x(Q);
    for(auto& i : x) i = in();

    CHT_offline_get_min<f64> cht(x, false);
    for(auto [c, r] : C) cht.add_line(2 * c, r * r - c * c);
    printer::precision(20);
    for(auto& p : x) {
        f64 ans = max<f64>(0, cht.query(p) - p * p);
        print(sqrtl(ans));
    }
}
accuracy: 1
time_ms: 190
memory_kb: 15684
final_rank: 9

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

using ld = long double;

const ld EPS = 1e-9;

int main() {
  int N; cin >> N;
  vector< array<ld, 2> > cir(N);
  for (int i = 0; i < N; ++i) {
    ld c, r; cin >> c >> r;
    cir[i] = {c, r};
  }
  sort(cir.begin(), cir.end());
  
  vector< tuple<int, ld, ld> > vec;
  for (int i = 0; i < N; ++i) {
    auto [d, R] = cir[i];
    
    while (1) {
      if (vec.empty()) {
        vec.push_back({i, d - R, d + R});
        break;
      }
      
      auto [j, left, right] = vec.back();
      auto [c, r] = cir[j];
      if (c + r < d - R + EPS) {
        // non intersect
        vec.push_back({i, d - R, d + R});
        break;
      }
      if (d + R < c + r + EPS)  {
        // contained
        break;
      }
      if (d - R < c - r + EPS) {
        // overlap
        vec.pop_back();
        continue;
      }
      
      ld x = (- R * R + d * d + r * r - c * c) / (2 * d - 2 * c);
      assert(x < right + EPS);
      if (x > left) {
        vec.pop_back();
        vec.push_back({j, left, x});
        vec.push_back({i, x, d + R});
        break;
      }
      else {
        vec.pop_back();
        continue;
      }
      
    }
  }
  
  // for (auto [i, left, right] : vec) {
  //   cout << i << " " << left << " " << right << endl;
  // }
  
  int Q; cin >> Q;
  vector< pair<ld, int> > query(Q);
  for (int q = 0; q < Q; ++q) {
    ld x; cin >> x;
    query[q] = {x, q};
  }
  sort(query.begin(), query.end());
  
  vector<ld> res(Q, 0.0);
  int now = 0;
  for (auto [x, id] : query) {
    res[id] = 0.0;
    while (now < (int)vec.size()) {
      auto [i, left, right] = vec[now];
      if (right < x - EPS) {now++; continue;}
      if (x < left - EPS) {res[id] = 0.0; break;}
      
      auto [c, r] = cir[i];
      ld h = sqrt(r * r - (c - x) * (c - x));
      res[id] = h;
      break;
    }
    
  }
  
  cout << fixed << setprecision(20);
  for (int q = 0; q < Q; ++q) {
    cout << res[q] << endl;
  }
  
  return 0;
}
accuracy: 1
time_ms: 270
memory_kb: 16140
final_rank: 10

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

using ld = long double;

const ld EPS = 1e-9;

int main() {
  int N; cin >> N;
  vector< array<ld, 2> > cir(N);
  for (int i = 0; i < N; ++i) {
    ld c, r; cin >> c >> r;
    cir[i] = {c, r};
  }
  sort(cir.begin(), cir.end());
  
  vector< tuple<int, ld, ld> > vec;
  for (int i = 0; i < N; ++i) {
    auto [d, R] = cir[i];
    
    while (1) {
      if (vec.empty()) {
        vec.push_back({i, d - R, d + R});
        break;
      }
      
      auto [j, left, right] = vec.back();
      auto [c, r] = cir[j];
      if (c + r < d - R + EPS) {
        // non intersect
        vec.push_back({i, d - R, d + R});
        break;
      }
      if (d + R < c + r + EPS)  {
        // contained
        break;
      }
      if (d - R < c - r + EPS) {
        // overlap
        vec.pop_back();
        continue;
      }
      
      ld x = (- R * R + d * d + r * r - c * c) / (2 * d - 2 * c);
      assert(x < right + EPS);
      if (x > left) {
        vec.pop_back();
        vec.push_back({j, left, x});
        vec.push_back({i, x, d + R});
        break;
      }
      else {
        vec.pop_back();
        continue;
      }
      
    }
  }
  
  // for (auto [i, left, right] : vec) {
  //   cout << i << " " << left << " " << right << endl;
  // }
  
  int Q; cin >> Q;
  vector< pair<ld, int> > query(Q);
  for (int q = 0; q < Q; ++q) {
    ld x; cin >> x;
    query[q] = {x, q};
  }
  sort(query.begin(), query.end());
  
  vector<ld> res(Q, 0.0);
  int now = 0;
  for (auto [x, id] : query) {
    res[id] = 0.0;
    while (now < (int)vec.size()) {
      auto [i, left, right] = vec[now];
      if (right + EPS < x) {now++; continue;}
      if (x < left - EPS) {res[id] = 0.0; break;}
      
      auto [c, r] = cir[i];
      ld h = sqrt(r * r - (c - x) * (c - x));
      res[id] = h;
      break;
    }
    
  }
  
  cout << fixed << setprecision(20);
  for (int q = 0; q < Q; ++q) {
    cout << res[q] << endl;
  }
  
  return 0;
}
accuracy: 1
time_ms: 270
memory_kb: 16592
final_rank: 12

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

using ld = long double;

const ld EPS = 1e-9;

int main() {
  int N; cin >> N;
  vector< array<ld, 2> > cir(N);
  for (int i = 0; i < N; ++i) {
    ld c, r; cin >> c >> r;
    cir[i] = {c, r};
  }
  sort(cir.begin(), cir.end());
  
  vector< tuple<int, ld, ld> > vec;
  for (int i = 0; i < N; ++i) {
    auto [d, R] = cir[i];
    
    while (1) {
      if (vec.empty()) {
        vec.push_back({i, d - R, d + R});
        break;
      }
      
      auto [j, left, right] = vec.back();
      auto [c, r] = cir[j];
      if (c + r < d - R + EPS) {
        // non intersect
        vec.push_back({i, d - R, d + R});
        break;
      }
      if (d + R < c + r + EPS)  {
        // contained
        break;
      }
      if (d - R < c - r + EPS) {
        // overlap
        vec.pop_back();
        continue;
      }
      
      ld x = (- R * R + d * d + r * r - c * c) / (2 * d - 2 * c);
      assert(x < right + EPS);
      if (x > left) {
        vec.pop_back();
        vec.push_back({j, left, x});
        vec.push_back({i, x, d + R});
        break;
      }
      else {
        vec.pop_back();
        continue;
      }
      
    }
  }
  
  // for (auto [i, left, right] : vec) {
  //   cout << i << " " << left << " " << right << endl;
  // }
  
  int Q; cin >> Q;
  vector< pair<ld, int> > query(Q);
  for (int q = 0; q < Q; ++q) {
    ld x; cin >> x;
    query[q] = {x, q};
  }
  sort(query.begin(), query.end());
  
  vector<ld> res(Q, 0.0);
  int now = 0;
  for (auto [x, id] : query) {
    res[id] = 0.0;
    while (now < (int)vec.size()) {
      auto [i, left, right] = vec[now];
      if (right < x + EPS) {now++; continue;}
      // if (x < left + EPS) {res[id] = 0.0; break;}
      
      auto [c, r] = cir[i];
      if (x < c - r + EPS) {res[id] = 0.0; break;}
      ld h = sqrt(r * r - (c - x) * (c - x));
      res[id] = h;
      break;
    }
    
  }
  
  cout << fixed << setprecision(20);
  for (int q = 0; q < Q; ++q) {
    cout << res[q] << endl;
  }
  
  return 0;
}
accuracy: 1
time_ms: 260
memory_kb: 17120
final_rank: 11

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

using ld = long double;

const ld EPS = 1e-9;

int main() {
  int N; cin >> N;
  vector< array<ld, 2> > cir(N);
  for (int i = 0; i < N; ++i) {
    ld c, r; cin >> c >> r;
    cir[i] = {c, r};
  }
  sort(cir.begin(), cir.end());
  
  vector< tuple<int, ld, ld> > vec;
  for (int i = 0; i < N; ++i) {
    auto [d, R] = cir[i];
    
    while (1) {
      if (vec.empty()) {
        vec.push_back({i, d - R, d + R});
        break;
      }
      
      auto [j, left, right] = vec.back();
      auto [c, r] = cir[j];
      if (c + r < d - R + EPS) {
        // non intersect
        vec.push_back({i, d - R, d + R});
        break;
      }
      if (d - R < c - r + EPS) {
        // overlap
        vec.pop_back();
        continue;
      }
      if (d + R < c + r + EPS)  {
        // contained
        break;
      }
      
      ld x = (- R * R + d * d + r * r - c * c) / (2 * d - 2 * c);
      if (x > left) {
        vec.pop_back();
        vec.push_back({j, left, x});
        vec.push_back({i, x, d + R});
        break;
      }
      else {
        vec.pop_back();
        continue;
      }
      
    }
  }
  
  // for (auto [i, left, right] : vec) {
  //   cout << i << " " << left << " " << right << endl;
  // }
  
  int Q; cin >> Q;
  vector< pair<ld, int> > query(Q);
  for (int q = 0; q < Q; ++q) {
    ld x; cin >> x;
    query[q] = {x, q};
  }
  sort(query.begin(), query.end());
  
  vector<ld> res(Q, 0.0);
  int now = 0;
  for (auto [x, id] : query) {
    res[id] = 0.0;
    while (now < (int)vec.size()) {
      auto [i, left, right] = vec[now];
      if (right < x + EPS) {now++; continue;}
      if (x < left + EPS) {res[id] = 0.0; break;}
      
      auto [c, r] = cir[i];
      ld h = sqrt(r * r - (c - x) * (c - x));
      res[id] = h;
      break;
    }
    
  }
  
  cout << fixed << setprecision(20);
  for (int q = 0; q < Q; ++q) {
    cout << res[q] << endl;
  }
  
  return 0;
}
accuracy: 0.18518518518518517
time_ms: 250
memory_kb: 10960
final_rank: 15

code_snippet: #include<bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
#define rep(i,n) for(ll i=0;i<ll(n);i++)

double EPS = 1e-12;
bool is_contain(double x, double y, double c, double r) {
    double d = (x - c) * (x - c) + y * y;
    return d <= r * r + EPS;
}

pair<double, double> crosspoint(double c1, double r1, double c2, double r2) {
    double x = (r1 * r1 - c1 * c1 + c2 * c2 - r2 * r2) / (2.0 * (c2 - c1));
    double y = r1 * r1 - (x - c1) * (x - c1);
    if (y < 0.0)return { x,0.0 };
    else return { x,sqrt(y) };
}


int main() {
    ll N;
    cin >> N;
    vector<pair<ll, ll>> MT(N);
    rep(i, N)cin >> MT[i].first >> MT[i].second;
    sort(MT.begin(), MT.end());
    deque<pair<ll, ll>> D;
    rep(i, N) {
        bool EG = 1;
        while (D.size() > 0) {
            pair<ll, ll> P = D.back();
            D.pop_back();
            if (is_contain(P.first - P.second, 0.0, MT[i].first, MT[i].second)) {
                continue;
            }
            else if (is_contain(MT[i].first + MT[i].second, 0.0, P.first, P.second)) {
                D.push_back(P);
                EG = 0;
                break;
            }
            else if (D.size() == 0) {
                D.push_back(P);
                break;
            }
            else {
                pair<ll, ll> NP = D.back();
                D.pop_back();
                if (P.first - NP.first > P.second + NP.second) {
                    D.push_back(NP);
                    D.push_back(P);
                    break;
                }
                pair<double, double> CP = crosspoint(NP.first, NP.second, P.first, P.second);
                if (is_contain(CP.first, CP.second, MT[i].first, MT[i].second)) {
                    D.push_back(NP);
                    continue;
                }
                else {
                    D.push_back(NP);
                    D.push_back(P);
                    break;
                }
                break;
            }
        }
        if (EG)D.push_back(MT[i]);
    }
    cout << fixed << setprecision(15);
    ll Q;
    cin >> Q;
    vector<pair<double, ll>> R(Q);
    rep(q, Q) {
        double x;
        cin >> x;
        R[q] = { x,q };
    }
    sort(R.begin(), R.end());
    vector<double> AN(Q, -1);
    rep(q, Q) {
        double x = R[q].first;
        while (D.size() > 1) {
            pair<ll, ll> P = D.front();
            D.pop_front();
            if (P.first + P.second < x)continue;
            pair<ll, ll> Q = D.front();
            if (Q.first - P.first > P.second + Q.second) {
                D.push_front(P);
                break;
            }
            pair<double, double> CP = crosspoint(P.first, P.second, Q.first, Q.second);
            if (CP.first < x)continue;
            else {
                D.push_front(P);
                break;
            }
        }
        if (D.size() == 0)AN[R[q].second] = 0.0;
        else if (!is_contain(x, 0.0, D.front().first, D.front().second))AN[R[q].second] = 0.0;
        else {
            double d = x - D.front().first;
            double r = D.front().second;
            AN[R[q].second] = sqrt(r * r - d * d);
        }
    }
    rep(q, Q)cout << AN[q] << endl;
}
accuracy: 1
time_ms: 230
memory_kb: 8708
final_rank: 5

code_snippet: #if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>
#include <cmath>
#include <cstdint>

auto& in = std::cin;
auto& out = std::cout;
#define all_range(C) std::begin(C), std::end(C)
const double PI = 3.141592653589793238462643383279502884197169399375105820974944;

int32_t N;
std::vector<std::pair<int, int>> mount;
std::vector<int> query;
using namespace std;
#define INF 200000000200000000
#define P pair<int64_t,int64_t>
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define all(V) V.begin(),V.end()
class ConvexHullTrick {
    bool minOrMax, lineMonotone;
    class Line {
    public:
        int64_t a, b;
        bool isquery;
        mutable std::function<const Line* ()> getSuc;
        bool operator<(const Line& x) const {
            if (isquery) {
                const Line* suc = next(this);
                if (suc == nullptr) return true;
                return (suc->a - x.a) * a + suc->b - x.b > 0;
            }
            if (x.isquery) {
                const Line* suc = next(this);
                if (suc == nullptr) return false;
                return (suc->a - a) * x.a + suc->b - b < 0;
            }
            return a < x.a;
        }
    };
    bool isbad(const std::set<Line>::iterator x) {
        if (x == st.begin() || next(x) == st.end())return false;
        auto pre = prev(x), nex = next(x);
        if (((*x).b - (*pre).b) * ((*nex).a - (*x).a) >= ((*nex).b - (*x).b) * ((*x).a - (*pre).a))return true;
        return false;
    }
    bool isbad(const std::vector<Line>::iterator x) {
        if (x == vec.begin() || next(x) == vec.end())return false;
        auto pre = prev(x), nex = next(x);
        if (((*x).b - (*pre).b) * ((*nex).a - (*x).a) >= ((*nex).b - (*x).b) * ((*x).a - (*pre).a))return true;
        return false;
    }
    std::set<Line> st;
    std::vector<Line> vec;
public:
    ConvexHullTrick(bool minormax = false, bool lineMonotone = false) :minOrMax(minormax), lineMonotone(lineMonotone) {}
    void addLine(int64_t a, int64_t b) {
        if (minOrMax) {
            a = -a; b = -b;
        }
        if (!lineMonotone) {
            auto pos = st.lower_bound({ a,-INF,false });
            if (pos != st.end()) {
                if ((*pos).a == a) {
                    if ((*pos).b <= b)return;
                    st.erase(pos);
                }
            }
            auto ite = st.insert({ a,b,false }).first;
            ite->getSuc = [=] {return next(ite) == st.end() ? nullptr : &*next(ite); };
            if (isbad(ite)) {
                st.erase(ite);
                return;
            }
            while (next(ite) != st.end() && isbad(next(ite)))st.erase(next(ite));
            while (ite != st.begin() && isbad(prev(ite)))st.erase(prev(ite));
        }
        else {
            if (!vec.empty()) {
                if (vec.back().a > a) {
                    cerr << "Line additions are not monotone" << endl;
                    exit(1);
                }
                if (vec.back().a == a) {
                    if (vec.back().b <= b)return;
                    vec.pop_back();
                }
            }
            vec.push_back({ a,b,false });
            auto ite = --vec.end();
            int index = vec.size() - 1;
            ite->getSuc = [this, index] {std::cout << vec.size() << endl; return index == vec.size() - 1 ? nullptr : &*(vec.begin() + index + 1); };
            while (ite != vec.begin() && isbad(prev(ite))) {
                *prev(ite) = vec.back();
                vec.pop_back();
                ite = --vec.end();
            }
        }
    }
    int64_t query(int64_t x) {
        if (!lineMonotone) {
            auto l = *st.lower_bound(Line{ x, 0,true });
            if (!minOrMax)return l.a * x + l.b;
            else return -l.a * x - l.b;
        }
        else {
            auto l = *std::lower_bound(vec.begin(), vec.end() - 1, Line({ x,0,true }));
            if (!minOrMax)return l.a * x + l.b;
            else return -l.a * x - l.b;
        }
    }
};


std::vector<double> result();
int main()
{
    using std::endl;
    in.sync_with_stdio(false);
    out.sync_with_stdio(false);
    in.tie(nullptr);
    out.tie(nullptr);

    in >> N;
    for (int i = 0; i < N; i++)
    {
        int c, r;
        in >> c >> r;
        mount.push_back({ c, r });
    }
    int q;
    in >> q;
    for (int i = 0; i < q; i++){
        int x;
        in >> x;
        query.push_back(x);
    }
    std::sort(mount.begin(), mount.end(), std::greater<>{});

    ConvexHullTrick lines(true, true);
    for (size_t i = 0; i < mount.size(); i++)
    {
        if (i > 0) {
            if (mount[i].first == mount[i - 1].first) { continue; }
        }
        int64_t r = mount[i].second;
        int64_t c = mount[i].first;
        lines.addLine(2 * c, r * r - c * c);
    }

    for (size_t i = 0; i < q; i++)
    {
        int64_t npos = query[i];
        long double me = std::sqrt((long double)std::max<int64_t>(0, lines.query(npos) - npos * npos));
        out
            << std::fixed << std::setprecision(29)
            << me << '\n';

    }

    return 0;
}
#endif
accuracy: 0.4074074074074074
time_ms: 140
memory_kb: 14340
final_rank: 14

code_snippet: #if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>
#include <cmath>

auto& in = std::cin;
auto& out = std::cout;
#define all_range(C) std::begin(C), std::end(C)
const double PI = 3.141592653589793238462643383279502884197169399375105820974944;

int32_t N;
std::vector<std::pair<int, int>> mount;
std::vector<int> query;

template< typename T, bool isMin >
struct ConvexHullTrickAddMonotone {
#define F first
#define S second
    using P = std::pair< T, T >;
    std::deque< P > H;

    ConvexHullTrickAddMonotone() = default;

    bool empty() const { return H.empty(); }

    void clear() { H.clear(); }

    inline int sgn(T x) { return x == 0 ? 0 : (x < 0 ? -1 : 1); }

    using D = long double;

    inline bool check(const P& a, const P& b, const P& c) {
        if (b.S == a.S || c.S == b.S)
            return sgn(b.F - a.F) * sgn(c.S - b.S) >= sgn(c.F - b.F) * sgn(b.S - a.S);

        return (b.F-a.F)*(c.S-b.S) >= (b.S-a.S)*(c.F-b.F);
        //return
        //    D(b.F - a.F) * sgn(c.S - b.S) / D(abs(b.S - a.S)) >=
        //    D(c.F - b.F) * sgn(b.S - a.S) / D(abs(c.S - b.S));
    }

    void add(T a, T b) {
        if (!isMin) a *= -1, b *= -1;
        P line(a, b);
        if (empty()) {
            H.emplace_front(line);
            return;
        }
        if (H.front().F <= a) {
            if (H.front().F == a) {
                if (H.front().S <= b) return;
                H.pop_front();
            }
            while (H.size() >= 2 && check(line, H.front(), H[1])) H.pop_front();
            H.emplace_front(line);
        }
        else {
            assert(a <= H.back().F);
            if (H.back().F == a) {
                if (H.back().S <= b) return;
                H.pop_back();
            }
            while (H.size() >= 2 && check(H[H.size() - 2], H.back(), line)) H.pop_back();
            H.emplace_back(line);
        }
    }

    inline T get_y(const P& a, const T& x) {
        return a.F * x + a.S;
    }

    T query(T x) {
        assert(!empty());
        int l = -1, r = H.size() - 1;
        while (l + 1 < r) {
            int m = (l + r) >> 1;
            if (get_y(H[m], x) >= get_y(H[m + 1], x)) l = m;
            else r = m;
        }
        if (isMin) return get_y(H[r], x);
        return -get_y(H[r], x);
    }

    T query_monotone_inc(T x) {
        assert(!empty());
        while (H.size() >= 2 && get_y(H.front(), x) >= get_y(H[1], x)) H.pop_front();
        if (isMin) return get_y(H.front(), x);
        return -get_y(H.front(), x);
    }

    T query_monotone_dec(T x) {
        assert(!empty());
        while (H.size() >= 2 && get_y(H.back(), x) >= get_y(H[H.size() - 2], x)) H.pop_back();
        if (isMin) return get_y(H.back(), x);
        return -get_y(H.back(), x);
    }

#undef F
#undef S
};


int main()
{
    using std::endl;
    in.sync_with_stdio(false);
    out.sync_with_stdio(false);
    in.tie(nullptr);
    out.tie(nullptr);

    in >> N;
    for (int i = 0; i < N; i++)
    {
        int c, r;
        in >> c >> r;
        mount.push_back({ c, -r });
    }
    int q;
    in >> q;
    for (int i = 0; i < q; i++){
        int x;
        in >> x;
        query.push_back(x);
    }
    std::sort(mount.begin(), mount.end());

    ConvexHullTrickAddMonotone<int64_t, false> lines;
    for (size_t i = 0; i < mount.size(); i++)
    {
        int64_t r = -mount[i].second;
        int64_t c = mount[i].first;
        lines.add(2 * c, r * r - c * c);
    }

    //std::ifstream ans("./10_test_02.ans");


    for (size_t i = 0; i < q; i++)
    {
        //double ansss = 0;
        //ans >> ansss;

        int64_t npos = query[i];
        long double me = std::sqrt((long double)std::max<int64_t>(0, lines.query(npos) - npos * npos));
        out
            << std::fixed << std::setprecision(29)
            << me << '\n';

        //auto diff = std::abs(ansss - me);
        //if (diff > 0.00000001) {
        //    std::cerr << "ERROR!\n";
        //}
    }

    return 0;
}
#endif
accuracy: 0.4074074074074074
time_ms: 140
memory_kb: 5308
final_rank: 13