# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
777009 | Rafi22 | Seesaw (JOI22_seesaw) | C++14 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}