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>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef long long ll;
#define int long long
#define sz(x) (int)(x.size())
#define debug(x) cerr << (#x) << ": " << (x) << endl
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
int n, k, m;
vector<int> a;
void solve() {
cin >> n;
a.clear(), a.resize(n);
for (auto &u: a) cin >> u;
vector<int> sum(n, 0);
int mid=n/2+n%2;
for (int i=0; i<mid; i++) sum[0]+=a[i];
for (int i=1; i<n; i++) {
sum[i]=sum[i-1]+a[(i+mid-1)%n]-a[i-1];
}
sum.insert(sum.end(), all(sum));
priority_queue<int, vector<int>, greater<int>> curr;
for (int i=0; i<mid; i++) curr.push(sum[i]);
unordered_map<int, int> retire;
int ans=0;
for (int i=mid; i<sz(sum); i++) {
ans=max(ans, curr.top());
curr.push(sum[i]);
retire[sum[i-mid]]++;
while (retire[curr.top()]>0) {
retire[curr.top()]--;
curr.pop();
}
}
cout << ans << endl;
return;
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
int tt=1;// cin >> tt;
while(tt--) 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... |