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;
struct frac
{
long long u, d;
bool operator<(frac ot) const
{
return (__int128)u * ot.d < (__int128)ot.u * d;
}
operator long double() { return (long double)u / d; }
};
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];
pair<frac, frac> B[n];
B[0] = { {ps[n], n}, {ps[n], n} };
for(int i = 1; i < n; ++i)
{
int s = 0, e = i;
while(s + 1 < e)
{
int mid = s + e >> 1;
if(frac{ps[n - i + mid] - ps[mid], n - i} < frac{ps[n], n}) s = mid;
else e = mid;
}
B[i] = { frac{ps[n - i + s] - ps[s], n - i}, frac{ps[n - i + s + 1] - ps[s + 1], n - i} };
}
sort(B, B + n);
frac r = B[n - 1].ff;
long double ans = r - B[0].ff;
for(int i = 0; i < n - 1; ++i)
{
r = max(r, B[i].ss);
ans = min(ans, r - B[i + 1].ff);
}
r = max(r, B[n - 1].ss);
ans = min(ans, r - B[n - 1].ff);
cout << fixed << setprecision(20) << ans;
}
Compilation message (stderr)
seesaw.cpp: In function 'int main()':
seesaw.cpp:47:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
47 | int mid = s + e >> 1;
| ~~^~~
# | 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... |