This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// In the name of God
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
typedef long long ll;
const int N = 1e6 + 5;
int n, v[N], s[N];
void solve() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> v[i];
v[i + n] = v[i];
}
int ans = 0;
multiset<int> st;
for (int i = 0; i < (n + 1) / 2; i++)
s[(n + 1) / 2 - 1] += v[i];
for (int i = (n + 1) / 2; i < 2 * n; i++) {
s[i] = s[i - 1] - v[i - (n + 1) / 2] + v[i];
}
for (int i = (n + 1) / 2 - 1; i <= 2 * ((n + 1) / 2 - 1); i++) {
st.insert(s[i]);
}
ans = *st.begin();
for (int i = (n + 1) / 2; i + (n + 1) / 2 - 1 < 2 * n; i++) {
st.erase(st.find(s[i - 1]));
st.insert(s[i + (n + 1) / 2 - 1]);
ans = max(ans, *st.begin());
}
cout << ans << '\n';
}
int32_t main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
solve();
return 0;
}
# | 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... |