제출 #1057232

#제출 시각아이디문제언어결과실행 시간메모리
1057232juicySeesaw (JOI22_seesaw)C++17
100 / 100
33 ms8884 KiB
#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif

const int N = 2e5 + 5;

int n;
int a[N];
long long pf[N];

double qry(int l, int r) {
  return (double) (pf[r] - pf[l - 1]) / (r - l + 1);
}

int main() {
  ios::sync_with_stdio(false); cin.tie(nullptr);

  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    pf[i] = pf[i - 1] + a[i];
  }
  double A = qry(1, n);
  vector<array<double, 2>> cands = {{A, A}};
  for (int l = 1; l < n; ++l) {
    int L = 1, R = n - l + 1, p = 0;
    while (L <= R) {
      int md = (L + R) / 2; 
      if (qry(md, md + l - 1) < A) {
        p = md;
        L = md + 1;
      } else {
        R = md - 1;
      }
    }
    cands.push_back({qry(p, p + l - 1), qry(p + 1, p + l)});
  }
  sort(cands.begin(), cands.end());
  double res = 1e9, mx = cands.back()[0];
  for (auto [x, y] : cands) {
    res = min(res, mx - x);
    mx = max(mx, y);
  }
  cout << fixed << setprecision(12) << res;
  return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...