This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
// #define int long long
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
#define kill(x) cout << x << "\n", exit(0);
#define pii pair<int, int>
#define endl "\n"
using namespace std;
typedef long long ll;
// typedef __int128_t lll;
typedef long double ld;
const int MAXN = (int)1e6 + 7;
const int MOD = (int)1e9 + 7;
const int INF = (int)1e9 + 7;
const int LG = 20;
int n, m, k, tmp, t, tmp2, tmp3, tmp4, u, v, w, flag, q, ans, flag2;
int arr[MAXN], ps[MAXN], dp[MAXN];
int sps[MAXN][LG];
inline int go_fw(int ind, int k) {
if (ind+k-1 <= n) return ps[ind+k-1]-ps[ind-1];
return ps[n]-ps[ind-1]+go_fw(1, k-(n-ind+1));
}
inline int get_mn(int v, int k) {
int res = INF;
for (int i=LG-1; i>=0; i--) {
if (k&(1<<i)) {
res = min(res, sps[v][i]);
v += (1<<i);
}
}
return res;
}
inline int solve(int ind) {
int j = ind, res = INF;
if (ind >= (n+1)/2) return get_mn(ind-(n+1)/2+1, (n+1)/2);
return min(get_mn(1, ind), get_mn(n-((n+1)/2-ind)+1, (n+1)/2-ind));
}
int32_t main() {
#ifdef LOCAL
freopen("inp.in", "r", stdin);
freopen("res.out", "w", stdout);
#else
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#endif
cin >> n;
for (int i=1; i<=n; i++) {
cin >> arr[i]; tmp += arr[i];
ps[i] = ps[i-1]+arr[i];
}
for (int i=1; i<=n; i++) sps[i][0] = go_fw(i, (n+1)/2);
for (int j=1; j<LG; j++) for (int i=1; i<=n; i++) sps[i][j] = min(sps[i][j-1], sps[i+(1<<(j-1))][j-1]);
ans = 0;
for (int i=1; i<=n; i++) ans = max(ans, solve(i));
cout << ans << endl;
return 0;
}
Compilation message (stderr)
hac.cpp: In function 'int solve(int)':
hac.cpp:57:9: warning: unused variable 'j' [-Wunused-variable]
57 | int j = ind, res = INF;
| ^
hac.cpp:57:18: warning: unused variable 'res' [-Wunused-variable]
57 | int j = ind, res = INF;
| ^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |