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 <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <tuple>
#include <iomanip>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define piii pair<int, pii>
#define plll pair<long long, pll>
#define tiii tuple<int, int, int>
#define tiiii tuple<int, int, int, int>
#define ff first
#define ss second
#define ee ss.ff
#define rr ss.ss
const int INF = (int)1e9 + 7;
using namespace std;
bool cmp(pll x, pll y)
{
return (__int128)x.ff * y.ss < (__int128)y.ff * x.ss;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n; cin >> n;
int A[n]; for(auto &i : A) cin >> i;
long long ps[n + 1]{}; for(int i = 1; i <= n; ++i) ps[i] = ps[i - 1] + A[i - 1];
pll t = {ps[n], n};
pll s = t;
int l = 0, r = n;
while(l + 1 < r)
{
if(cmp(t, pll{ps[r] - ps[l + 1], r - l - 1})) --r;
else ++l;
if(cmp(pll{ps[r] - ps[l], r - l}, s)) s = pll{ps[r] - ps[l], r - l};
}
long double ans = (long double)t.ff / t.ss - (long double)s.ff / s.ss;
s = t;
l = 0, r = n;
while(l + 1 < r)
{
if(cmp(pll{ps[r - 1] - ps[l], r - l - 1}, t)) ++l;
else --r;
if(cmp(s, pll{ps[r] - ps[l], r - l})) s = pll{ps[r] - ps[l], r - l};
}
ans = min(ans, (long double)s.ff / s.ss - (long double)t.ff / t.ss);
cout << fixed << setprecision(20) << ans;
}
# | 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... |