#include <bits/stdc++.h>
using namespace std;
template<class A, class B>
ostream& operator<<(ostream& o, const pair<A, B>& p) {return o << '(' << p.first << ", " << p.second << ')';}
template<size_t Index = 0, typename... Types>
ostream& printTupleElements(ostream& o, const tuple<Types...>& t) {if constexpr (Index < sizeof...(Types)){if(Index > 0){o << ", ";}o << get<Index>(t);printTupleElements<Index + 1>(o, t);}return o;}
template<typename... Types>
ostream& operator<<(ostream& o, const tuple<Types...>& t){o << "(";printTupleElements(o, t);return o << ")";}
template<class T>
auto operator<<(ostream& o, const T& x) -> decltype(x.end(), o){o << '{';bool first = true;for (const auto& e : x){if (!first){o << ", ";}o << e;first = false;} return o << '}';}
#define DEBUG
#ifdef DEBUG
#define fastio()
#define debug(x...) cerr << "[" #x "]: ", [](auto... $) {((cerr << $ << "; "), ...); }(x), cerr << '\n'
#define check(x) if (!(x)) { cerr << "Check failed: " << #x << " in line " << __LINE__ << endl; exit(1); }
#else
#define fastio() ios_base::sync_with_stdio(0); cin.tie(0);
#define debug(...)
#define check(x)
#endif
typedef long long ll;
#define pi pair<int, int>
#define pl pair<ll, ll>
#define st first
#define nd second
#define vi vector<int>
#define vll vector<ll>
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size
constexpr int base = (1 << 19);
int tri[2 * base];
void set_tree() {
for(int i = 0; i < 2 * base; i++) {
tri[i] = 1e9;
}
}
void upd(int l, int r, int x) {
l += base;
r += base;
while(l <= r) {
if(l & 1) {
tri[l] = min(tri[l], x);
}
if(!(r & 1)) {
tri[r] = min(tri[r], x);
}
l = (l + 1) / 2;
r = (r - 1) / 2;
}
}
int que(int v) {
v += base;
int ans = 1e9;
while(v > 0) {
ans = min(ans, tri[v]);
v /= 2;
}
return ans;
}
void solve() {
int n;
cin >> n;
vi tab(n);
for(auto &x : tab) {
cin >> x;
}
vi s = tab;
for(int i = 1; i < n; i++) {
s[i] += s[i - 1];
}
auto get_sum = [&](int l, int r) {
if(l > r) {
return s[n - 1] - (s[l - 1] - s[r]);
}
if(!l) {
return s[r];
}
return s[r] - s[l - 1];
};
set_tree();
for(int i = 0; i < n; i++) {
int r = (i + (n + 1) / 2 - 1) % n;
int sum = get_sum(i, r);
if(r >= i) {
upd(i, r, sum);
}
else {
upd(i, n - 1, sum);
upd(0, r, sum);
}
}
int ans = 0;
for(int i = 0; i < n; i++) {
ans = max(ans, que(i));
}
cout << ans << '\n';
}
int main() {
fastio();
int t;
//cin >> t;
t = 1;
while(t--) {
solve();
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4308 KB |
Output is correct |
2 |
Correct |
2 ms |
4308 KB |
Output is correct |
3 |
Correct |
2 ms |
4308 KB |
Output is correct |
4 |
Correct |
2 ms |
4308 KB |
Output is correct |
5 |
Correct |
2 ms |
4308 KB |
Output is correct |
6 |
Correct |
2 ms |
4308 KB |
Output is correct |
7 |
Correct |
2 ms |
4308 KB |
Output is correct |
8 |
Correct |
2 ms |
4308 KB |
Output is correct |
9 |
Correct |
2 ms |
4308 KB |
Output is correct |
10 |
Correct |
2 ms |
4308 KB |
Output is correct |
11 |
Correct |
2 ms |
4308 KB |
Output is correct |
12 |
Correct |
2 ms |
4308 KB |
Output is correct |
13 |
Correct |
2 ms |
4308 KB |
Output is correct |
14 |
Correct |
2 ms |
4308 KB |
Output is correct |
15 |
Correct |
2 ms |
4308 KB |
Output is correct |
16 |
Correct |
2 ms |
4308 KB |
Output is correct |
17 |
Correct |
2 ms |
4308 KB |
Output is correct |
18 |
Correct |
2 ms |
4308 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4308 KB |
Output is correct |
2 |
Correct |
2 ms |
4308 KB |
Output is correct |
3 |
Correct |
2 ms |
4308 KB |
Output is correct |
4 |
Correct |
2 ms |
4308 KB |
Output is correct |
5 |
Correct |
2 ms |
4308 KB |
Output is correct |
6 |
Correct |
2 ms |
4308 KB |
Output is correct |
7 |
Correct |
2 ms |
4308 KB |
Output is correct |
8 |
Correct |
2 ms |
4308 KB |
Output is correct |
9 |
Correct |
2 ms |
4308 KB |
Output is correct |
10 |
Correct |
2 ms |
4308 KB |
Output is correct |
11 |
Correct |
2 ms |
4308 KB |
Output is correct |
12 |
Correct |
2 ms |
4308 KB |
Output is correct |
13 |
Correct |
2 ms |
4308 KB |
Output is correct |
14 |
Correct |
2 ms |
4308 KB |
Output is correct |
15 |
Correct |
2 ms |
4308 KB |
Output is correct |
16 |
Correct |
2 ms |
4308 KB |
Output is correct |
17 |
Correct |
2 ms |
4308 KB |
Output is correct |
18 |
Correct |
2 ms |
4308 KB |
Output is correct |
19 |
Correct |
2 ms |
4308 KB |
Output is correct |
20 |
Correct |
2 ms |
4308 KB |
Output is correct |
21 |
Correct |
2 ms |
4308 KB |
Output is correct |
22 |
Correct |
4 ms |
4308 KB |
Output is correct |
23 |
Correct |
3 ms |
4436 KB |
Output is correct |
24 |
Correct |
3 ms |
4308 KB |
Output is correct |
25 |
Correct |
3 ms |
4436 KB |
Output is correct |
26 |
Correct |
3 ms |
4436 KB |
Output is correct |
27 |
Correct |
2 ms |
4308 KB |
Output is correct |
28 |
Correct |
2 ms |
4308 KB |
Output is correct |
29 |
Correct |
2 ms |
4308 KB |
Output is correct |
30 |
Correct |
3 ms |
4436 KB |
Output is correct |
31 |
Correct |
3 ms |
4428 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4308 KB |
Output is correct |
2 |
Correct |
3 ms |
4308 KB |
Output is correct |
3 |
Correct |
3 ms |
4436 KB |
Output is correct |
4 |
Correct |
28 ms |
5036 KB |
Output is correct |
5 |
Correct |
68 ms |
5956 KB |
Output is correct |
6 |
Correct |
74 ms |
6284 KB |
Output is correct |
7 |
Correct |
90 ms |
6744 KB |
Output is correct |
8 |
Correct |
149 ms |
8284 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4308 KB |
Output is correct |
2 |
Correct |
2 ms |
4308 KB |
Output is correct |
3 |
Correct |
2 ms |
4308 KB |
Output is correct |
4 |
Correct |
2 ms |
4308 KB |
Output is correct |
5 |
Correct |
2 ms |
4308 KB |
Output is correct |
6 |
Correct |
2 ms |
4308 KB |
Output is correct |
7 |
Correct |
2 ms |
4308 KB |
Output is correct |
8 |
Correct |
2 ms |
4308 KB |
Output is correct |
9 |
Correct |
2 ms |
4308 KB |
Output is correct |
10 |
Correct |
2 ms |
4308 KB |
Output is correct |
11 |
Correct |
2 ms |
4308 KB |
Output is correct |
12 |
Correct |
2 ms |
4308 KB |
Output is correct |
13 |
Correct |
2 ms |
4308 KB |
Output is correct |
14 |
Correct |
2 ms |
4308 KB |
Output is correct |
15 |
Correct |
2 ms |
4308 KB |
Output is correct |
16 |
Correct |
2 ms |
4308 KB |
Output is correct |
17 |
Correct |
2 ms |
4308 KB |
Output is correct |
18 |
Correct |
2 ms |
4308 KB |
Output is correct |
19 |
Correct |
2 ms |
4308 KB |
Output is correct |
20 |
Correct |
2 ms |
4308 KB |
Output is correct |
21 |
Correct |
2 ms |
4308 KB |
Output is correct |
22 |
Correct |
4 ms |
4308 KB |
Output is correct |
23 |
Correct |
3 ms |
4436 KB |
Output is correct |
24 |
Correct |
3 ms |
4308 KB |
Output is correct |
25 |
Correct |
3 ms |
4436 KB |
Output is correct |
26 |
Correct |
3 ms |
4436 KB |
Output is correct |
27 |
Correct |
2 ms |
4308 KB |
Output is correct |
28 |
Correct |
2 ms |
4308 KB |
Output is correct |
29 |
Correct |
2 ms |
4308 KB |
Output is correct |
30 |
Correct |
3 ms |
4436 KB |
Output is correct |
31 |
Correct |
3 ms |
4428 KB |
Output is correct |
32 |
Correct |
2 ms |
4308 KB |
Output is correct |
33 |
Correct |
3 ms |
4308 KB |
Output is correct |
34 |
Correct |
3 ms |
4436 KB |
Output is correct |
35 |
Correct |
28 ms |
5036 KB |
Output is correct |
36 |
Correct |
68 ms |
5956 KB |
Output is correct |
37 |
Correct |
74 ms |
6284 KB |
Output is correct |
38 |
Correct |
90 ms |
6744 KB |
Output is correct |
39 |
Correct |
149 ms |
8284 KB |
Output is correct |
40 |
Correct |
5 ms |
4436 KB |
Output is correct |
41 |
Correct |
7 ms |
4556 KB |
Output is correct |
42 |
Correct |
10 ms |
4588 KB |
Output is correct |
43 |
Correct |
59 ms |
5972 KB |
Output is correct |
44 |
Correct |
149 ms |
8268 KB |
Output is correct |
45 |
Correct |
28 ms |
5188 KB |
Output is correct |
46 |
Correct |
87 ms |
6716 KB |
Output is correct |
47 |
Correct |
146 ms |
8272 KB |
Output is correct |
48 |
Correct |
159 ms |
8312 KB |
Output is correct |
49 |
Correct |
143 ms |
8312 KB |
Output is correct |
50 |
Correct |
134 ms |
8312 KB |
Output is correct |