#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx,avx2")
#include <bits/stdc++.h>
#define ios ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define ull unsigned long long
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define sz size()
using namespace std;
const double pi = 2 * acos(0.0);
const ll N=1e6+7, M=998244353;
ll a[N], pr[N];
void solve()
{
int n;
cin >> n;
for (int i=0;i<n;i++) {
cin >> a[i];
pr[i]=pr[max(0, i-1)]+a[i];
}
ll ans=0;
for (int i=0;i<n;i++){
int l=i, r=i;
int lb=(n+1)/2, rb=n/2;
int lf, rg;
ll sum=0;
if (l-lb+1 < 0){
lf=n+(l-lb+1);
// cout << n << " " << l-lb+1 << "\n";
if (lf == 0) sum=pr[l]+pr[n-1];
else sum=pr[l]+(pr[n-1]-pr[lf-1]);
}
else {
lf=l-lb+1;
if (lf == 0) sum=pr[l];
else sum=pr[l]-pr[lf-1];
}
// cout << sum << " ";
ll sum1=sum;
sum=0;
if ((r+lb-1) > (n-1)){
rg=(r+lb-1) % (n-1);
rg--;
if (r-1 < 0) sum=pr[n-1]+pr[rg];
sum=(pr[n-1]-pr[r-1])+pr[rg];
}
else {
if (r-1 < 0) sum=pr[r+lb-1];
else sum=pr[l+rb-1]-pr[r-1];
}
// cout << sum <<"\n";
ans=max(ans, min(sum, sum1));
}
cout << ans;
return ;
}
int main(){
ios;
int t=1;
// cin >> t;
while (t--){
solve();
cout << "\n";
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |