#include<bits/stdc++.h>
using namespace std;
ifstream fin("seesaw.in");
#define cin fin
#define double long double
vector<double> ord;
int n;
int a[200005];
double tot,ans=1000000000;
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;
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));
//cout<<fixed<<setprecision(15)<<sum/(n-i)<<"\n";
}
ans = min(ans, mxm-le);
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];
}
for(int i=1;i<=n;i++)
{
double cv = 0;
for(int j=i;j<=n;j++)
{
cv += a[j];
ord.push_back(cv/(j-i+1));
}
}
sort(ord.begin(),ord.end());
while(ord[ord.size()-1]>tot/n)
ord.pop_back();
/*for(int i=0;i<=19396720;i+=5000)
{
cout<<i<<" ";
cout<<fixed<<setprecision(15)<<verif(i)<<"\n";
}
return 0;*/
/*double st,dr,mij1,mij2;
st=0;
dr=tot/n;
for(int i=0;i<100;i++)
{
mij1 = st + (dr-st)/3;
mij2 = mij1 + (dr-st)/3;
//if(verif(mij1)==verif(mij2)) cout<<"--- equal ---\n";
if(verif(mij1)<verif(mij2))
dr=mij2;
else
st=mij1;
}*/
int st,dr,mij1,mij2;
st=0;
dr=ord.size()-1;
while(dr-st+1>=1000)
{
mij1 = st + (dr-st+1)/3;
mij2 = mij1 + (dr-st+1)/3;
if(verif(ord[mij1])<verif(ord[mij2]))
dr=mij2;
else
st=mij1;
}
for(int i=st;i<=dr;i++)
ans = min(ans, verif(ord[i]));
cout<<fixed<<setprecision(15)<<ans;
return 0;
}
/**
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |