This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// Wounds should become scars but I'm cracked instead U+1FAE0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef long double ld;
#define all(x) (x).begin(),(x).end()
#define X first
#define Y second
#define sep ' '
#define endl '\n'
#define debug(x) cerr << #x << ": " << x << endl;
const ll MAXN = 1e6 + 10;
int A[MAXN], n;
inline ld calc(int l, int r) {
ll s = 0;
for (int i = l; i <= r; i++)
s += A[i];
return ld(s) / (r - l + 1);
}
inline ld solve(bool flag) {
int l = 1, r = n;
ld tl = calc(l, r), tr = calc(l, r);
while (l < r) {
if (flag) l++;
else r--;
tl = min(tl, calc(l, r));
tr = max(tr, calc(l, r));
flag ^= 1;
}
return tr - tl;
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) cin >> A[i];
cout << setprecision(10) << fixed << min(solve(0), solve(1)) << endl;
return 0;
}
# | 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... |