#include <iostream>
#include <limits>
#include <vector>
using namespace std;
int t[4000'000];
void Build(const vector<int>& a, int v, int vl, int vr)
{
if (vl == vr)
{
t[v] = a[vr];
return;
}
int vm = (vl + vr) / 2;
Build(a, v * 2, vl, vm);
Build(a, v * 2 + 1, vm + 1, vr);
t[v] = min(t[v * 2], t[v * 2 + 1]);
}
int Min(int v, int vl, int vr, int l, int r)
{
if (vl > r || l > vr)
return numeric_limits<int>::max();
if (l <= vl && vr <= r)
return t[v];
int vm = (vl + vr) / 2;
return min(Min(v * 2, vl, vm, l, r), Min(v * 2 + 1, vm + 1, vr, l, r));
}
int main()
{
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; ++i)
cin >> a[i];
vector<int> b(3 * n), pref(3 * n);
for (int i = 0; i < 3 * n; ++i)
{
b[i] = a[i % n];
pref[i] = (i ? pref[i - 1] : 0) + b[i];
}
vector<int> sum(2 * n);
for (int i = 0; i < 2 * n; ++i)
sum[i] = pref[i + (n + 1) / 2 - 1] - (i ? pref[i - 1] : 0);
Build(sum, 1, 0, 2 * n - 1);
int ans = 0;
for (int i = n; i < 2 * n; ++i)
ans = max(ans, Min(1, 0, 2 * n - 1, i - (n + 1) / 2 + 1, i));
cout << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
256 KB |
Output is correct |
4 |
Correct |
5 ms |
256 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
256 KB |
Output is correct |
15 |
Correct |
5 ms |
256 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
256 KB |
Output is correct |
4 |
Correct |
5 ms |
256 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
256 KB |
Output is correct |
15 |
Correct |
5 ms |
256 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
19 |
Correct |
5 ms |
384 KB |
Output is correct |
20 |
Correct |
5 ms |
384 KB |
Output is correct |
21 |
Correct |
5 ms |
384 KB |
Output is correct |
22 |
Correct |
7 ms |
512 KB |
Output is correct |
23 |
Correct |
9 ms |
640 KB |
Output is correct |
24 |
Correct |
6 ms |
512 KB |
Output is correct |
25 |
Correct |
8 ms |
692 KB |
Output is correct |
26 |
Correct |
8 ms |
640 KB |
Output is correct |
27 |
Correct |
5 ms |
256 KB |
Output is correct |
28 |
Correct |
5 ms |
256 KB |
Output is correct |
29 |
Correct |
5 ms |
256 KB |
Output is correct |
30 |
Correct |
7 ms |
640 KB |
Output is correct |
31 |
Correct |
7 ms |
640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
8 ms |
640 KB |
Output is correct |
4 |
Correct |
58 ms |
5496 KB |
Output is correct |
5 |
Correct |
132 ms |
12280 KB |
Output is correct |
6 |
Correct |
175 ms |
14328 KB |
Output is correct |
7 |
Correct |
218 ms |
20728 KB |
Output is correct |
8 |
Correct |
358 ms |
28280 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
256 KB |
Output is correct |
4 |
Correct |
5 ms |
256 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
256 KB |
Output is correct |
15 |
Correct |
5 ms |
256 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
19 |
Correct |
5 ms |
384 KB |
Output is correct |
20 |
Correct |
5 ms |
384 KB |
Output is correct |
21 |
Correct |
5 ms |
384 KB |
Output is correct |
22 |
Correct |
7 ms |
512 KB |
Output is correct |
23 |
Correct |
9 ms |
640 KB |
Output is correct |
24 |
Correct |
6 ms |
512 KB |
Output is correct |
25 |
Correct |
8 ms |
692 KB |
Output is correct |
26 |
Correct |
8 ms |
640 KB |
Output is correct |
27 |
Correct |
5 ms |
256 KB |
Output is correct |
28 |
Correct |
5 ms |
256 KB |
Output is correct |
29 |
Correct |
5 ms |
256 KB |
Output is correct |
30 |
Correct |
7 ms |
640 KB |
Output is correct |
31 |
Correct |
7 ms |
640 KB |
Output is correct |
32 |
Correct |
5 ms |
384 KB |
Output is correct |
33 |
Correct |
5 ms |
384 KB |
Output is correct |
34 |
Correct |
8 ms |
640 KB |
Output is correct |
35 |
Correct |
58 ms |
5496 KB |
Output is correct |
36 |
Correct |
132 ms |
12280 KB |
Output is correct |
37 |
Correct |
175 ms |
14328 KB |
Output is correct |
38 |
Correct |
218 ms |
20728 KB |
Output is correct |
39 |
Correct |
358 ms |
28280 KB |
Output is correct |
40 |
Correct |
11 ms |
1024 KB |
Output is correct |
41 |
Correct |
16 ms |
1664 KB |
Output is correct |
42 |
Correct |
25 ms |
2048 KB |
Output is correct |
43 |
Correct |
143 ms |
12280 KB |
Output is correct |
44 |
Correct |
347 ms |
28408 KB |
Output is correct |
45 |
Correct |
67 ms |
6264 KB |
Output is correct |
46 |
Correct |
214 ms |
20344 KB |
Output is correct |
47 |
Correct |
351 ms |
28280 KB |
Output is correct |
48 |
Correct |
375 ms |
28640 KB |
Output is correct |
49 |
Correct |
307 ms |
27896 KB |
Output is correct |
50 |
Correct |
317 ms |
27896 KB |
Output is correct |