/*input
5
1 2 3 4 5
*/
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>
using namespace std;
#define sp ' '
#define endl '\n'
#define fi first
#define se second
#define mp make_pair
#define int long long
#define N 500005
int n;
int a[N];
int sum[N];
int f[N];
int getsum(int l, int r) {
return sum[r] - sum[l - 1];
}
int ceil(int x, int y) {
int ret = x / y;
if (x % y) ret++;
return ret;
}
void update(int k, int l, int r, int pos, int val) {
if (pos < l || r < pos) return;
if (l == r) {
f[pos] = val;
return;
}
int mid = (l + r) / 2;
update(k * 2, l, mid, pos, val); update(k * 2 + 1, mid + 1, r, pos, val);
f[k] = max(f[k * 2], f[k * 2 + 1]);
}
int get(int k, int l, int r, int L, int R) {
if (r < L || R < l) return 0;
if (L <= l && r <= R) return f[k];
int mid = (l + r) / 2;
return max(get(k * 2, l, mid, L, R), get(k * 2 + 1, mid + 1, r, L, R));
}
// https://oj.uz/problem/view/BOI15_hac
signed main() {
ios_base::sync_with_stdio(false); cin.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] + a[i];
int ans = 0;
for (int i = 1; i <= n; i++) {
int last = i + n / 2 - 1;
if (last <= n)
update(1, 1, n, i, getsum(i, last));
else
update(1, 1, n, i, getsum(i, n) + getsum(1, n / 2 - (n - i + 1)));
}
for (int i = 1; i <= n; i++) {
int last = i - n / 2;
if (last < 0) last += n;
int res = 1e18;
if (last < i) {
res = get(1, 1, n, i + 1, n);
res = min(res, get(1, 1, n, 1, last));
}
else {
res = get(1, 1, n, i + 1, last);
}
ans = max(ans, res);
}
cout << ans << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
13892 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
13892 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
13892 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
13892 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |