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
// Hope is last to die
#include <bits/stdc++.h>
using namespace std;
// #pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx2")
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define pb push_back
// #define int long long
#define S second
#define F first
#define mp make_pair
#define smax(x, y) (x) = max((x), (y))
#define smin(x, y) (x) = min((x), (y))
#define all(x) (x).begin(), (x).end()
const int maxn = 5e5 + 5;
const int inf = 1e9 + 7;
int n, a[maxn], ps[maxn];
multiset<int> st;
int get(int i){
int res = ps[min(n, i + (n + 1) / 2 - 1)] - ps[i - 1];
if(i + (n + 1) / 2 - 1 > n){
res += ps[i + (n + 1) / 2 - 1 - n];
}
return res;
}
int32_t main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n;
for(int i = 1; i <= n; i++){
cin >> a[i];
ps[i] = ps[i - 1] + a[i];
}
st.insert(get(1));
for(int i = n / 2 + 2; i <= n; i++){
st.insert(get(i));
}
int ans = 0;
for(int i = 1; i <= n; i++){
smax(ans, (*st.begin()));
int j = i - (n - 1) / 2;
if(j <= 0) j += n;
st.erase(st.find(get(j)));
if(i < n) st.insert(get(i + 1));
}
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... |