Submission #1308841

#TimeUsernameProblemLanguageResultExecution timeMemory
1308841Euclid73Balloons (CEOI11_bal)C++20
100 / 100
193 ms4400 KiB
#include <bits/stdc++.h>
using namespace std;

#define ll long long

const ll MAXN=2e5+5;

/*
store stack of the ballons that we might possibly hit,
with heights in decreasing order from the first
*/

double findR(pair<double, double> a, double b)
{
    return ((a.first-b)*(a.first-b))/(4*a.second);
}

ll n;
double radii[MAXN];
stack<pair<double, double>> st;

int main()
{
    cin >> n;
    for (int i=0; i<n; i++)
    {
        double x, r;
        cin >> x >> r;
        double maxR=r;
        while (!st.empty())
        {
            pair<double, double> cur=st.top();
            double curR=findR(cur, x);  
            maxR=min(maxR, curR);
            if (maxR>=cur.second)
            {
                st.pop();
                continue;
            }
            break;
        }
        radii[i]=maxR;
        st.push({x, maxR});
    }
    cout << fixed << setprecision(3);
    for (int i=0; i<n; i++)
    {
        cout << radii[i] << "\n";
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...