# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1127006 | gawr_gura | Seesaw (JOI22_seesaw) | C++20 | 69 ms | 328 KiB |
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 1e6 + 5;
int n;
double a[N];
signed main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define task "seesaw"
if(fopen(task ".inp","r")) {
freopen(task ".inp","r",stdin);
freopen(task ".out","w",stdout);
}
cin >> n;
for(int i = 1; i <= n; i ++) cin >> a[i];
double ans = (double)(2e9);
for(int msk = 0; msk < (1 << n); msk ++) {
double sum = 0;
int l = 1, r = n;
for(int i = 1; i <= n; i ++) sum += a[i];
double cnt = n;
double mi = (1.0 * sum) / (1.0 * cnt);
double mx = (1.0 * sum) / (1.0 * cnt);
for(int k = 1; k < n; k ++) if(msk >> (k - 1) & 1) {
sum -= a[r];
cnt--;
mx = max(mx, (1.0 * sum) / (1.0 * cnt));
mi = min(mi, (1.0 * sum) / (1.0 * cnt));
r --;
} else {
sum -= a[l];
cnt--;
mx = max(mx, (1.0 * sum) / (1.0 * cnt));
mi = min(mi, (1.0 * sum) / (1.0 * cnt));
l ++;
}
ans = min(ans, mx - mi);
}
cout << setprecision(9) << fixed << ans;
}
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... |