#include <bits/stdc++.h>
using namespace std;
vector<pair<double,double>> tab;
const double eps = 1e-7;
// Corrected function: returns true if new circle intersects the last one
bool czy(double a, double r)
{
double x = tab.back().first - a;
double r_prev = tab.back().second;
double dy = r - r_prev;
double sum = r + r_prev;
return x*x + dy*dy < sum*sum;
}
// Binary search to find the largest radius that does NOT intersect the last circle
double find_best_radius(double a, double b)
{
double low = 0.0;
double high = b;
if (!czy(a, high)) return high; // max radius does not intersect
for (int i = 0; i < 60; ++i) // 60 iterations = safe for doubles
{
double mid = (low + high) / 2.0;
if (czy(a, mid)) high = mid; // intersects → go lower
else low = mid; // does not intersect → go higher
}
return low;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vector<double> wyn;
for (int i = 0; i < n; ++i)
{
double a, b;
cin >> a >> b;
// Pop previous circles if new one can replace them
while (!tab.empty())
{
double best = find_best_radius(a, b);
if (best + eps < tab.back().second) break;
tab.pop_back();
}
double r_final;
if (tab.empty())
{
r_final = b;
}
else
{
r_final = find_best_radius(a, b);
}
wyn.push_back(r_final);
tab.push_back({a, r_final});
}
cout << fixed << setprecision(3);
for (double v : wyn)
cout << v << '\n';
return 0;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |