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 <stdio.h>
#define N 200000
double min(double a, double b) { return a < b ? a : b; }
double max(double a, double b) { return a > b ? a : b; }
unsigned int X = 12345;
int rand_() {
return (X *= 3) >> 1;
}
double xx[N], yy[N];
void sort(int *hh, int l, int r) {
while (l < r) {
int i = l, j = l, k = r, h = hh[l + rand_() % (r - l)], tmp;
while (j < k)
if (xx[hh[j]] == xx[h])
j++;
else if (xx[hh[j]] < xx[h]) {
tmp = hh[i], hh[i] = hh[j], hh[j] = tmp;
i++, j++;
} else {
k--;
tmp = hh[j], hh[j] = hh[k], hh[k] = tmp;
}
sort(hh, l, i);
l = k;
}
}
int main() {
static int aa[N], hh[N];
static long long ss[N + 1];
int n, m, h, i, k, lower, upper;
double y, ans;
scanf("%d", &n);
ss[0] = 0;
for (i = 0; i < n; i++) {
scanf("%d", &aa[i]);
ss[i + 1] = ss[i] + aa[i];
}
m = 0;
for (k = 1; k < n; k++) {
lower = 0, upper = n - k + 1;
while (upper - lower > 1) {
i = (lower + upper) / 2;
if ((double) (ss[i + k] - ss[i]) / k <= (double) ss[n] / n)
lower = i;
else
upper = i;
}
i = lower;
if ((double) (ss[i + k] - ss[i]) / k == (double) ss[n] / n)
continue;
xx[m] = (double) (ss[i + k] - ss[i]) / k, yy[m] = (double) (ss[i + 1 + k] - ss[i + 1]) / k, m++;
}
if (m == 0) {
printf("0\n");
return 0;
}
for (h = 0; h < m; h++)
hh[h] = h;
sort(hh, 0, m);
y = (double) ss[n] / n;
ans = y - xx[hh[0]];
for (h = 0; h < m; h++) {
y = max(y, yy[hh[h]]);
ans = min(ans, y - (h + 1 < m ? xx[hh[h + 1]] : (double) ss[n] / n));
}
printf("%.12f\n", ans);
return 0;
}
Compilation message (stderr)
seesaw.c: In function 'main':
seesaw.c:41:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
41 | scanf("%d", &n);
| ^~~~~~~~~~~~~~~
seesaw.c:44:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
44 | scanf("%d", &aa[i]);
| ^~~~~~~~~~~~~~~~~~~
# | 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... |