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 the God
#include <bits/stdc++.h>
#define ll long long
#define int long long
#define pb push_back
#define F first
#define S second
#define mp make_pair
#define pii pair <int, int>
#define smin(x, y) (x) = min((x), (y))
#define smax(x, y) (x) = max((x), (y))
#define all(x) (x).begin(), (x).end()
using namespace std;
// #pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx2")
const int inf = 1e9+7;
const int mod = 998244353;
const int maxn = 5e5+5;
int n, v[maxn];
multiset <int> st;
int g(int i, int x = (n+1)/2) {
if (i+x-1 < n) {
// if (i == 1) cout << "HI\n" << ' ' << v[i+x-1] << ' ' << (i-1 >= 0 ? v[i-1] : 0) << '\n';
return v[i+x-1]-(i-1 >= 0 ? v[i-1] : 0);
}
int j = (i+x-1)%n;
return v[j]+v[n-1]-(i-1 >= 0 ? v[i-1] : 0);
}
int p(int i, int x = (n+1)/2) {
i = (i-x+1+3*n)%n;
return g(i);
}
int32_t main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n;
for (int i = 0; i < n; i++) {
cin >> v[i];
if (i) v[i] += v[i-1];
}
for (int i = 0; i < (n+1)/2; i++) st.insert(g(i));
int ans = 0;
for (int i = 0; i < n; i++) {
int j = ((n+1)/2-1+i)%n;
smax(ans, *st.begin());
st.erase(p(j));
st.insert(g((j+1)%n));
}
cout << ans << '\n';
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... |