#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2")
#include<bits/stdc++.h>
using namespace std;
const int maxn=2000000+10;
long long all[maxn],ps[maxn],n;
long double md;
pair<long double,long double>stf[maxn];
long double calmian(int len,int l){
int r=l+len-1;
if(r>n){
return 1e9+5;
}
long double ret=ps[r]-ps[l-1];
ret/=len;
return ret;
}
void calstf(int ind){
int low=1,high=n+1,mid;
while(high-low>1){
mid=(high+low)>>1;
if(calmian(ind,mid)<=md){
low=mid;
}
else{
high=mid;
}
}
stf[ind].first=calmian(ind,low);
stf[ind].second=calmian(ind,high);
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n;
for(int i=1;i<=n;i++){
cin>>all[i];
ps[i]=ps[i-1]+all[i];
}
md=(long double)ps[n]/n;
long double mx=md;
vector<pair<long double,int>>v;
for(int i=1;i<=n;i++){
calstf(i);
v.push_back(make_pair(stf[i].first,i));
}
sort(v.rbegin(),v.rend());
long double res=1e9;
while((int)v.size()>0){
//cout<<mx<<" "<<v.back().first<<" "<<v.back().second<<endl;
res=min(res,mx-v.back().first);
mx=max(mx,stf[v.back().second].second);
v.pop_back();
}
cout<<setprecision(10)<<fixed<<res<<endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4440 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4440 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
2 ms |
4696 KB |
Output is correct |
9 |
Correct |
2 ms |
4700 KB |
Output is correct |
10 |
Correct |
2 ms |
4700 KB |
Output is correct |
11 |
Correct |
2 ms |
4700 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4440 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
2 ms |
4696 KB |
Output is correct |
9 |
Correct |
2 ms |
4700 KB |
Output is correct |
10 |
Correct |
2 ms |
4700 KB |
Output is correct |
11 |
Correct |
2 ms |
4700 KB |
Output is correct |
12 |
Correct |
91 ms |
21196 KB |
Output is correct |
13 |
Correct |
103 ms |
19644 KB |
Output is correct |
14 |
Correct |
90 ms |
20916 KB |
Output is correct |
15 |
Correct |
91 ms |
20408 KB |
Output is correct |
16 |
Correct |
90 ms |
20420 KB |
Output is correct |