#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((P[sr+k-1]-P[sr-1])*(ll)n<=P[n]*(ll)k)
{
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
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});
| ~~~^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
300 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
300 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
2 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
2 ms |
504 KB |
Output is correct |
11 |
Correct |
2 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
300 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
2 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
2 ms |
504 KB |
Output is correct |
11 |
Correct |
2 ms |
468 KB |
Output is correct |
12 |
Incorrect |
107 ms |
11744 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |