This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// Source: https://oj.uz/problem/view/BOI15_hac
//
#include "bits/stdc++.h"
using namespace std;
#define s second
#define f first
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef vector<int> vi;
#define FOR(i, a, b) for (int i = (a); i<b; i++)
bool ckmin(int& a, int b){ return b < a ? a = b, true : false; }
bool ckmax(int& a, int b){ return b > a ? a = b, true : false; }
const int N = 5e5 + 10;
int a[N];
int res[N];
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
FOR(i, 0, n) cin >> a[i];
int sum = 0;
FOR(i, 0, (n+1)/2) sum += a[i];
int i = 0;
int j = (n+1)/2;
for (;i < n;) {
res[i] = sum;
sum += a[j]-a[i];
i++;
j = (j + 1) % n;
}
multiset<int> window;
FOR(i, 0, (n + 1) / 2) window.insert(res[i]);
int ans = 0;
i = 0;
j = (n+1)/2;
for (;i < n;) {
ans = max(ans, *window.begin());
window.erase(window.find(res[i]));
window.insert(res[j]);
i++;
j = (j + 1) % n;
}
cout << ans << endl;
}
# | 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... |