提交时间:2023-08-09 21:12:29

运行 ID: 81699

#include<bits/stdc++.h> using namespace std; int n, a[200010]; long long ans, s[200010]; long long sum(int l, int r) { return s[r] - s[l - 1]; } int main() { cin >>n; for (int i = 1;i <= n; i++) { cin >> a[i]; a[n + i] = a[i]; } for (int i = 1; i <= n *2; i++) { s[i] = s[i - 1] + a[i]; } for (int i = 1;i <= n; i++) { int j = i + n - 1; int l = i, r = j; while (l < r) { int mid = (l + r + 1) / 2; if (3 * sum(i, mid) > sum(1, n)) { r = mid - 1; } else{ l = mid; } } int tl = l + 1, tr = j; while (tl < tr) { int mid = (tl + tr) / 2; if (3 * sum(l + 1, mid) < sum(1, n)) { tl = mid + 1; } else { tr = mid; } } long long a = sum(i, l); long long b = sum(l + 1, tl); long long c = sum(tl + 1, j); ans = max(ans, min({a, b, c})); } cout << ans << endl; return 0; }