#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(), (x).end()
#define MP make_pair
const int N = 100500;
int n;
int a[N], p[N];
int get_sum(int l, int r){
if (l <= r){
return p[r] - (l == 0 ? 0 : p[l - 1]);
} else {
return p[r] + (p[n - 1] - p[l - 1]);
}
}
void solve(){
cin >> n;
for (int i = 0; i < n; i++){
cin >> a[i];
p[i] = a[i] + (i > 0 ? p[i - 1] : 0);
}
int ans = 0;
for (int i = 0; i < 100; i++){
int mx = 0;
for (int l = i + 1; l < n; l++){
int r = (l + n / 2 - 1) % n;
if (l <= r && l <= i && i <= r) continue;
if (l > r && (l <= i || i <= r)) continue;
mx = max(mx, get_sum(l, r));
}
for (int l = 0; l < i; l++){
int r = (l + n / 2 - 1) % n;
if (l <= r && l <= i && i <= r) continue;
if (l > r && (l <= i || i <= r)) continue;
mx = max(mx, get_sum(l, r));
}
ans = max(ans, get_sum(0, n - 1) - mx);
}
cout << ans << endl;
}
int main() {
ios_base::sync_with_stdio(false);
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
solve();
return 0;
}
Compilation message
hac.cpp: In function 'void solve()':
hac.cpp:17:19: warning: array subscript -1 is below array bounds of 'int [100500]' [-Warray-bounds]
17 | return p[r] + (p[n - 1] - p[l - 1]);
| ~~~^
hac.cpp:11:11: note: while referencing 'p'
11 | int a[N], p[N];
| ^
hac.cpp:17:42: warning: array subscript -1 is below array bounds of 'int [100500]' [-Warray-bounds]
17 | return p[r] + (p[n - 1] - p[l - 1]);
| ~~~~~~~^
hac.cpp:11:11: note: while referencing 'p'
11 | int a[N], p[N];
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
3 ms |
340 KB |
Output is correct |
4 |
Correct |
48 ms |
936 KB |
Output is correct |
5 |
Incorrect |
8 ms |
1068 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |