이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |