This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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<120;i++)
{
mij1 = st + (dr-st)/3;
mij2 = mij1 + (dr-st)/3;
if(verif(mij1)<verif(mij2))
dr=mij2;
else
st=mij1;
}
cout<<fixed<<setprecision(12)<<verif((st+dr)/2);
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... |