Submission #739572

#TimeUsernameProblemLanguageResultExecution timeMemory
739572alexddSeesaw (JOI22_seesaw)C++17
1 / 100
2 ms212 KiB
#include<bits/stdc++.h>
using namespace std;
#define double long double
int n;
int a[200005];
double tot;
double verif(double le)///lungimea minima daca barycentrul nu poate trece in stanga lui le
{
    double sum = tot,mxm;
    int pozs=1,pozd=n;
    mxm = tot/n;
    for(int i=1;i<=n-1;i++)
    {
        if((sum-a[pozd])/(n-i)>=le)
        {
            sum-=a[pozd];
            pozd--;
        }
        else
        {
            sum-=a[pozs];
            pozs++;
        }
        mxm = max(mxm, sum/(n-i));
    }
    return mxm-le;
}
signed main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);

    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        tot+=a[i];
    }
    double st,dr,mij1,mij2;
    st=0;
    dr=tot/n;
    for(int i=0;i<2000;i++)
    {
        mij1 = st + (dr-st)/3;
        mij2 = mij1 + (dr-st)/3;
        if(verif(mij1)<verif(mij2))
            dr=mij2;
        else
            st=mij1;
    }
    cout<<fixed<<setprecision(15)<<verif((st+dr)/2);
    return 0;
}
/**



*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...