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 endl '\n'
#define st first
#define nd second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ld long double
ll mod=1000000007;
int inf=1000000007;
ll infl=1000000000000000007;
const int N=200007;
ll a[N];
ll P[N];
bool cmp(pair<ll,ll>l,pair<ll,ll>r)
{
return (ld)l.st/(ld)l.nd<(ld)r.st/(ld)r.nd;
}
int cnt[N];
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>a[i];
P[i]=P[i-1]+a[i];
}
vector<pair<ll,ll>>V;
V.pb({P[n],n});
for(int k=1;k<n;k++)
{
int l=1,r=n-k+1,sr,p;
while(l<=r)
{
sr=(l+r)/2;
if((ld)(P[sr+k-1]-P[sr-1])/(ld)k<=(ld)P[n]/(ld)n)
{
p=sr;
l=sr+1;
}
else r=sr-1;
}
V.pb({P[p+k-1]-P[p-1],k});
if(p+k<=n) V.pb({P[p+k]-P[p],k});
}
sort(all(V),cmp);
ld ans=inf;
int j=0,ile=0;
for(int i=0;i<sz(V);i++)
{
while(j<sz(V)&&ile<n)
{
cnt[V[j].nd]++;
if(cnt[V[j].nd]==1) ile++;
j++;
}
if(ile==n)
{
ans=min(ans,(ld)V[j-1].st/(ld)V[j-1].nd-(ld)V[i].st/(ld)V[i].nd);
}
cnt[V[i].nd]--;
if(cnt[V[i].nd]==0) ile--;
}
cout<<fixed<<setprecision(9)<<ans;
return 0;
}
Compilation message (stderr)
seesaw.cpp: In function 'int main()':
seesaw.cpp:57:36: warning: 'p' may be used uninitialized in this function [-Wmaybe-uninitialized]
57 | if(p+k<=n) V.pb({P[p+k]-P[p],k});
| ~~~^
# | 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... |