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;
using ll = long long;
const int maxn = 5e5+5;
int n;
int v[2*maxn];
int pre[2*maxn];
int main()
{
ios_base::sync_with_stdio(false); cin.tie(NULL);
cin >> n;
for (int i = 0; i < n; i++) {
cin >> v[i];
v[i+n] = v[i];
}
pre[0] = v[0];
for (int i = 1; i < 2*n; i++) {
pre[i] = pre[i-1] + v[i];
}
int total = pre[n-1];
if (n <= 5000) {
int res = 0;
for (int i = 0; i < n; i++) {
int maxSum = 0;
for (int j = i+n/2; j < i+n; j++) {
maxSum = max(maxSum,pre[j]-pre[j-n/2]);
}
res = max(res,total-maxSum);
}
cout << res << '\n';
}
else {
int res = 0;
for (int i = 0; i < 1; i++) {
int maxSum = 0;
for (int j = i+n/2; j < i+n; j++) {
maxSum = max(maxSum,pre[j]-pre[j-n/2]);
}
res = max(res,total-maxSum);
}
cout << res << '\n';
}
}
# | 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... |