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 ll long double
#define fr first
#define sc second
const int mxn=2e5+5;
int n,a[mxn];
ll ps[mxn],mx,ans=1e9;
vector<pair<ll,ll>>v;
int main(){
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
ps[i]=ps[i-1]+a[i];
}
for(int i=1;i<n;i++){
int L=1,R=n-i+1;
while(R-L>1){
int mid=(L+R)/2;
ll x=(ps[mid+i-1]-ps[mid-1])/(ll)i;
if(x<=(ps[n]/(ll)n))
L=mid;
else
R=mid;
}
ll x=(ps[L+i-1]-ps[L-1])/i,y=(ps[L+i]-ps[L])/(ll)i;
v.push_back({x,y});
//cout<<x<<" "<<y<<endl;
}
v.push_back({ps[n]/(ll)n,ps[n]/(ll)n});
sort(v.begin(),v.end());
mx=v.back().fr;
for(auto i:v){
ll L=i.fr,R=mx;
ans=min(ans,R-L);
//cout<<L<<" "<<R<<endl;
mx=max(mx,i.sc);
}
cout<<setprecision(10);
cout<<ans<<'\n';
}
# | 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... |