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;
const int MAXN = 5e5 + 7;
int sumpref[MAXN];
int n;
int sum(int a, int b){
return sumpref[b] - sumpref[a-1];
}
int solve(){
int res = 0;
int bestabs = 2e9;
int k = n/2;
for(int i = 1; i + k <= n; i++){
if(abs(sum(i, k+i-1) - (sumpref[n] - sum(i, k+i-1))) < bestabs){
res = max(sum(i, k+i-1), sumpref[n] - sum(i, k+i-1));
bestabs = abs(sum(i, k+i-1) - (sumpref[n] - sum(i, k+i-1)));
}
else if(abs(sum(i, k+i-1) - (sumpref[n] - sum(i, k+i-1))) <= bestabs)
res = max(max(res, sum(i, k+i-1)), sumpref[n] - sum(i, k+i-1));
}
return res;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for(int i = 1; i <= n; i++){
cin >> sumpref[i];
sumpref[i] += sumpref[i-1];
}
cout << solve() << 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... |