이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
typedef long long ll;
typedef long double ld;
#define int ll
int mod = 998244353;
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
int total = 0;
int k = n/2;
vector<int> arr(2*n);
for(int i = 0; i < n; ++i){
int x;
cin >> x;
arr[i] = arr[n+i] = x;
total += x;
}
vector<pair<int,int>> sliding(n, {0,0});
int sum = 0;
for(int i = 0, j = 0; i < n; ++i){
while(j-i<k){
sum += arr[j];
++j;
}
sliding[i].ff = sum;
sum -= arr[i];
}
reverse(arr.begin(), arr.end());
sum = 0;
for(int i = 0, j = 0; i < n; ++i){
while(j-i<k){
sum += arr[j];
++j;
}
sliding[n-i-1].ss = sum;
sum -= arr[i];
}
int ans = max(total-max(sliding[n].ss, sliding[1].ff), total-max(sliding[n-1].ss, sliding[0].ff));
for(int i = 1; i < n-1; ++i){
ans = max(ans, total-max(sliding[i-1].ss, sliding[i+1].ff));
}
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... |