#include <bits/stdc++.h>
#define ll long long
#define pii pair <ll, ll>
#define st first
#define nd second
#define rep(i, n, m) for (ll i = n; i <= m; i ++)
#define rrep(i, n, m) for (ll i = n; i >= m; i --)
#define file "test"
using namespace std;
const long long N = 2e5 + 7;
const long long INF = 1e18;
const long long MOD = 2e9 + 11;
const long long base = 311;
const long double eps = 1e-10;
ll n, a[N];
bool is_smaller(pii x, pii y) {
return x.st * y.nd <= x.nd * y.st;
}
long double checkL(int l, int r, int n) {
ll s = 0;
rep(i, 1, n) s += a[i];
pii pivot = {s, n};
pii ans = {s, n};
while (l < r) {
if (is_smaller(pii(s - a[l], n - 1), pivot)) {
s -= a[l]; n --; l ++;
if (is_smaller(pii(s, n), ans))
ans = pii(s, n);
continue;
}
s -= a[r]; n --; r --;
if (is_smaller(pii(s, n), ans))
ans = pii(s, n);
}
long double x = -ans.st * pivot.nd + ans.nd * pivot.st, y = pivot.nd * ans.nd;
return x / y;
}
long double checkR(int l, int r, int n) {
ll s = 0;
rep(i, 1, n) s += a[i];
pii pivot = {s, n};
pii ans = {s, n};
while (l < r) {
if (is_smaller(pivot, pii(s - a[r], n - 1))) {
s -= a[r]; n --; r --;
if (is_smaller(ans, pii(s, n)))
ans = pii(s, n);
continue;
}
s -= a[l]; n --; l ++;
if (is_smaller(ans, pii(s, n)))
ans = pii(s, n);
}
long double x = ans.st * pivot.nd - ans.nd * pivot.st, y = pivot.nd * ans.nd;
// << "R: " << x << ' ' << y << '\n';
return x / y;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
// freopen(file".inp", "r", stdin);
// freopen(file".out", "w", stdout);
#endif // ONLINE_JUDGE
cin >> n;
rep(i, 1, n)
cin >> a[i];
cout << setprecision(10) << fixed << min(checkL(1, n, n), checkR(1, n, n));
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |