# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1067376 | TimDee | Seesaw (JOI22_seesaw) | C++17 | 59 ms | 12268 KiB |
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 int long long
#define forn(i,n) for(int i=0; i<n; ++i)
#define vii(a,n) vector<int> a(n); forn(i,n) cin>>a[i];
#define f first
#define s second
#define pb push_back
#define all(x) x.begin(),x.end()
const double eps = 1e-9;
void solve() {
int n; cin>>n;
vii(a,n);
vector<pair<double,int>> v;
int s=0; forn(i,n) s+=a[i];
double c = 1.0*s/n;
int l=0, r=n-1;
while (l<=r) {
int m=r-l+1;
v.pb({1.0*s/m,m-1});
if (l==r) break;
double z = 1.0*(s-a[r])/(m-1);
if (z>=c) {
s-=a[r]; --r;
} else {
s-=a[l]; ++l;
}
}
s=0, l=0, r=n-1; forn(i,n) s+=a[i];
while (l<=r) {
int m=r-l+1;
v.pb({1.0*s/m,m-1});
if (l==r) break;
double z = 1.0*(s-a[l])/(m-1);
if (z<=c) {
s-=a[l]; ++l;
} else {
s-=a[r]; --r;
}
}
sort(all(v));
//for(auto&x:v) cout<<'('<<x.f<<','<<x.s<<") ";
vector<int> cnt(n);
int tot=0;
r=0;
double ans=a[n-1]-a[0];
forn(i,v.size()) {
while (r<v.size() && tot<n) {
tot+=!cnt[v[r].s];
++cnt[v[r].s];
++r;
}
if (tot==n) ans=min(ans,v[r-1].f - v[i].f);
--cnt[v[i].s];
tot-=!cnt[v[i].s];
}
cout<<fixed<<setprecision(10)<<ans<<'\n';
}
int32_t main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
solve();
}
Compilation message (stderr)
# | 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... |