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 <iostream>
#include <vector>
#include "stdio.h"
#pragma GCC optimize("Ofast,O3,unroll-loops")
using namespace std;
#define int long long
signed main(){
ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#ifdef WTF
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
freopen("error.txt", "w", stderr);
#endif
int n; cin >> n;
vector <int> a(n + 1);
for(int i = 1; i <= n; i ++){
cin >> a[i];
}
vector <int> pr(n + 1, 0), sf(n + 2, 0);
for(int i = 1; i <= n; i ++){
pr[i] = pr[i - 1] + a[i];
}
for(int i = n; i >= 1; i --){
sf[i] = sf[i + 1] + a[i];
}
int ans = 0;
for(int i = 1; i <= n; i ++){
int rg = 0, lf = 0;
int cnt = n / 2;
if(i + cnt <= n) rg = pr[i + cnt] - pr[i];
else {
rg = pr[n] - pr[i];
rg += pr[cnt - (n - i)];
}
if(i - cnt >= 1) lf = sf[i - cnt] - sf[i];
else{
lf = sf[1] - sf[i];
lf += sf[n - (cnt - (i - 1)) + 1];
}
ans = max(ans, pr[n] - max(lf, rg));
}
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... |