Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
81699 | 吴思睿 | cake | C++ | 通过 | 100 | 50 MS | 2600 KB | 919 | 2023-08-09 21:12:29 |
#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; }