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;
typedef long long ll;
#define PUB push_back
int N, defend;
ll data[1500005],
total = 0,
ans = 0;
ll prefsum[1500005];
ll hitungScore(int ind){
int strL, finL;
int strR, finR;
ll scoreDef,
scoreL, scoreR;
finL = ind-1;
strL = finL-defend+1;
strR = ind+1;
finR = strR+defend-1;
scoreL = prefsum[finL]-prefsum[strL-1];
scoreR = prefsum[finR]-prefsum[strR-1];
scoreDef = max(scoreL, scoreR);
return total-scoreDef;
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> N;
defend = N/2;
for(int i=0;i<N;i++){
cin >> data[i];
total += data[i];
data[i+N] = data[i];
data[i+2*N] = data[i];
}
prefsum[0] = data[0];
for(int i=1;i<3*N;i++){
prefsum[i] = data[i]+prefsum[i-1];
}
for(int i=N;i<2*N;i++){
ans = max(ans, hitungScore(i));
}
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... |