fork download
  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. using namespace std;
  6. #define re(i, n) for (int i=0; i<n; i++)
  7. #define re1(i, n) for (int i=1; i<=n; i++)
  8. #define re2(i, l, r) for (int i=l; i<r; i++)
  9. #define re3(i, l, r) for (int i=l; i<=r; i++)
  10. #define rre(i, n) for (int i=n-1; i>=0; i--)
  11. #define rre1(i, n) for (int i=n; i>0; i--)
  12. #define rre2(i, r, l) for (int i=r-1; i>=l; i--)
  13. #define rre3(i, r, l) for (int i=r; i>=l; i--)
  14. #define ll long long
  15. const double zero = 1e-7;
  16. const int MAXN = 300010, INF = ~0U >> 2;
  17. int n, A[MAXN];
  18. double res;
  19. void init()
  20. {
  21. scanf("%d", &n);
  22. rre(i, n) scanf("%d", &A[i]);
  23. }
  24. void solve()
  25. {
  26. double x0 = 0, x1 = 0, m1 = A[0], x2 = 0, m2;
  27. re2(i, 1, n-1) {
  28. m2 = A[i];
  29. x2 = (m1 * x2 + m2 * (x2 - 1)) / (m1 + m2);
  30. m1 += m2;
  31. }
  32. if (n > 1) x2 -= 1; res = x1 - x2; m1 = A[0];
  33. re2(i, 1, n-1) {
  34. x1 = x0 + 1; m2 = A[i]; x0 = (m1 * x0 + m2 * x1) / (m1 + m2);
  35. m1 += m2; x2 += (m2 + m2) / m1;
  36. if (x1 - x2 - zero > res) res = x1 - x2 - zero;
  37. }
  38. if (res < -zero) res = 0;
  39. }
  40. void pri()
  41. {
  42. printf("%.6lf\n", res);
  43. }
  44. int main()
  45. {
  46. init();
  47. solve();
  48. pri();
  49. return 0;
  50. }
Success #stdin #stdout 0.01s 3900KB
stdin
3
1
1
9
stdout
1.900000