Submission #871009

#TimeUsernameProblemLanguageResultExecution timeMemory
871009Trisanu_DasSeesaw (JOI22_seesaw)C++17
67 / 100
2041 ms4712 KiB
#include <bits/stdc++.h> using namespace std; int A[200005], n; long long pref[200005]; long double ans; long double calc(int l, int r) { return (long double)(pref[r] - pref[l - 1]) / (r - l + 1); } long double solve(long double max_r) { int l = 1, r = n; long double tl = calc(l, r), tr = calc(l, r); while (l < r) { long double tll = min(tl, calc(l + 1, r)), tlr = max(tr, calc(l + 1, r)); if (tlr <= max_r) l++; else r--; tl = min(tl, calc(l, r)); tr = max(tr, calc(l, r)); if (tr - tl >= ans) return tr - tl; } return tr - tl; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n; for (int i = 1; i <= n; i++) { cin >> A[i]; pref[i] = pref[i - 1] + A[i]; } ans = A[n] - A[1]; for (int l = 1; l <= n; l++) for (int r = l; r <= n; r++) ans = min(ans, solve(calc(l, r))); cout << setprecision(10) << fixed << ans << '\n'; }

Compilation message (stderr)

seesaw.cpp: In function 'long double solve(long double)':
seesaw.cpp:16:15: warning: unused variable 'tll' [-Wunused-variable]
   16 |   long double tll = min(tl, calc(l + 1, r)), tlr = max(tr, calc(l + 1, r));
      |               ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...