#include <bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace std;
const int Nmax = 5e5 + 10;
int n;
long long s[Nmax];
vector <int> cands[Nmax];
int f[Nmax];
pair <int, int> best;
int main() {
ios :: sync_with_stdio(0); cin.tie(0);
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> s[i];
s[i] += s[i - 1];
}
memset(f, -1, sizeof(f));
f[0] = 0;
cands[1].push_back(0);
for (int i = 1; i <= n; ++i) {
for (auto j: cands[i]) best = max(best, {f[j] + 1, j});
f[i] = best.first;
int t = lower_bound(s + 1, s + n + 1, s[i] * 2 - s[best.second]) - s;
cands[t].push_back(i);
}
cout << f[n];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
13928 KB |
Output is correct |
2 |
Correct |
8 ms |
14000 KB |
Output is correct |
3 |
Correct |
7 ms |
13900 KB |
Output is correct |
4 |
Correct |
7 ms |
13900 KB |
Output is correct |
5 |
Correct |
7 ms |
13900 KB |
Output is correct |
6 |
Correct |
7 ms |
13900 KB |
Output is correct |
7 |
Correct |
7 ms |
13900 KB |
Output is correct |
8 |
Correct |
7 ms |
14048 KB |
Output is correct |
9 |
Correct |
8 ms |
13900 KB |
Output is correct |
10 |
Correct |
7 ms |
13940 KB |
Output is correct |
11 |
Correct |
7 ms |
13900 KB |
Output is correct |
12 |
Correct |
7 ms |
13932 KB |
Output is correct |
13 |
Correct |
7 ms |
13900 KB |
Output is correct |
14 |
Correct |
7 ms |
13900 KB |
Output is correct |
15 |
Correct |
7 ms |
13900 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
13928 KB |
Output is correct |
2 |
Correct |
8 ms |
14000 KB |
Output is correct |
3 |
Correct |
7 ms |
13900 KB |
Output is correct |
4 |
Correct |
7 ms |
13900 KB |
Output is correct |
5 |
Correct |
7 ms |
13900 KB |
Output is correct |
6 |
Correct |
7 ms |
13900 KB |
Output is correct |
7 |
Correct |
7 ms |
13900 KB |
Output is correct |
8 |
Correct |
7 ms |
14048 KB |
Output is correct |
9 |
Correct |
8 ms |
13900 KB |
Output is correct |
10 |
Correct |
7 ms |
13940 KB |
Output is correct |
11 |
Correct |
7 ms |
13900 KB |
Output is correct |
12 |
Correct |
7 ms |
13932 KB |
Output is correct |
13 |
Correct |
7 ms |
13900 KB |
Output is correct |
14 |
Correct |
7 ms |
13900 KB |
Output is correct |
15 |
Correct |
7 ms |
13900 KB |
Output is correct |
16 |
Correct |
7 ms |
14028 KB |
Output is correct |
17 |
Correct |
8 ms |
14028 KB |
Output is correct |
18 |
Correct |
8 ms |
14044 KB |
Output is correct |
19 |
Correct |
7 ms |
13976 KB |
Output is correct |
20 |
Correct |
8 ms |
14036 KB |
Output is correct |
21 |
Correct |
7 ms |
14028 KB |
Output is correct |
22 |
Correct |
9 ms |
14028 KB |
Output is correct |
23 |
Correct |
8 ms |
14028 KB |
Output is correct |
24 |
Correct |
7 ms |
14036 KB |
Output is correct |
25 |
Correct |
7 ms |
14028 KB |
Output is correct |
26 |
Correct |
7 ms |
14040 KB |
Output is correct |
27 |
Correct |
7 ms |
14028 KB |
Output is correct |
28 |
Correct |
8 ms |
14028 KB |
Output is correct |
29 |
Correct |
7 ms |
14028 KB |
Output is correct |
30 |
Correct |
7 ms |
14004 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
13928 KB |
Output is correct |
2 |
Correct |
8 ms |
14000 KB |
Output is correct |
3 |
Correct |
7 ms |
13900 KB |
Output is correct |
4 |
Correct |
7 ms |
13900 KB |
Output is correct |
5 |
Correct |
7 ms |
13900 KB |
Output is correct |
6 |
Correct |
7 ms |
13900 KB |
Output is correct |
7 |
Correct |
7 ms |
13900 KB |
Output is correct |
8 |
Correct |
7 ms |
14048 KB |
Output is correct |
9 |
Correct |
8 ms |
13900 KB |
Output is correct |
10 |
Correct |
7 ms |
13940 KB |
Output is correct |
11 |
Correct |
7 ms |
13900 KB |
Output is correct |
12 |
Correct |
7 ms |
13932 KB |
Output is correct |
13 |
Correct |
7 ms |
13900 KB |
Output is correct |
14 |
Correct |
7 ms |
13900 KB |
Output is correct |
15 |
Correct |
7 ms |
13900 KB |
Output is correct |
16 |
Correct |
7 ms |
14028 KB |
Output is correct |
17 |
Correct |
8 ms |
14028 KB |
Output is correct |
18 |
Correct |
8 ms |
14044 KB |
Output is correct |
19 |
Correct |
7 ms |
13976 KB |
Output is correct |
20 |
Correct |
8 ms |
14036 KB |
Output is correct |
21 |
Correct |
7 ms |
14028 KB |
Output is correct |
22 |
Correct |
9 ms |
14028 KB |
Output is correct |
23 |
Correct |
8 ms |
14028 KB |
Output is correct |
24 |
Correct |
7 ms |
14036 KB |
Output is correct |
25 |
Correct |
7 ms |
14028 KB |
Output is correct |
26 |
Correct |
7 ms |
14040 KB |
Output is correct |
27 |
Correct |
7 ms |
14028 KB |
Output is correct |
28 |
Correct |
8 ms |
14028 KB |
Output is correct |
29 |
Correct |
7 ms |
14028 KB |
Output is correct |
30 |
Correct |
7 ms |
14004 KB |
Output is correct |
31 |
Correct |
7 ms |
14028 KB |
Output is correct |
32 |
Correct |
7 ms |
14032 KB |
Output is correct |
33 |
Correct |
8 ms |
14132 KB |
Output is correct |
34 |
Correct |
8 ms |
14132 KB |
Output is correct |
35 |
Correct |
8 ms |
14136 KB |
Output is correct |
36 |
Correct |
9 ms |
14032 KB |
Output is correct |
37 |
Correct |
8 ms |
14032 KB |
Output is correct |
38 |
Correct |
9 ms |
14032 KB |
Output is correct |
39 |
Correct |
7 ms |
14036 KB |
Output is correct |
40 |
Correct |
9 ms |
14180 KB |
Output is correct |
41 |
Correct |
8 ms |
14032 KB |
Output is correct |
42 |
Correct |
7 ms |
14032 KB |
Output is correct |
43 |
Correct |
8 ms |
14032 KB |
Output is correct |
44 |
Correct |
8 ms |
14048 KB |
Output is correct |
45 |
Correct |
8 ms |
14140 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
13928 KB |
Output is correct |
2 |
Correct |
8 ms |
14000 KB |
Output is correct |
3 |
Correct |
7 ms |
13900 KB |
Output is correct |
4 |
Correct |
7 ms |
13900 KB |
Output is correct |
5 |
Correct |
7 ms |
13900 KB |
Output is correct |
6 |
Correct |
7 ms |
13900 KB |
Output is correct |
7 |
Correct |
7 ms |
13900 KB |
Output is correct |
8 |
Correct |
7 ms |
14048 KB |
Output is correct |
9 |
Correct |
8 ms |
13900 KB |
Output is correct |
10 |
Correct |
7 ms |
13940 KB |
Output is correct |
11 |
Correct |
7 ms |
13900 KB |
Output is correct |
12 |
Correct |
7 ms |
13932 KB |
Output is correct |
13 |
Correct |
7 ms |
13900 KB |
Output is correct |
14 |
Correct |
7 ms |
13900 KB |
Output is correct |
15 |
Correct |
7 ms |
13900 KB |
Output is correct |
16 |
Correct |
7 ms |
14028 KB |
Output is correct |
17 |
Correct |
8 ms |
14028 KB |
Output is correct |
18 |
Correct |
8 ms |
14044 KB |
Output is correct |
19 |
Correct |
7 ms |
13976 KB |
Output is correct |
20 |
Correct |
8 ms |
14036 KB |
Output is correct |
21 |
Correct |
7 ms |
14028 KB |
Output is correct |
22 |
Correct |
9 ms |
14028 KB |
Output is correct |
23 |
Correct |
8 ms |
14028 KB |
Output is correct |
24 |
Correct |
7 ms |
14036 KB |
Output is correct |
25 |
Correct |
7 ms |
14028 KB |
Output is correct |
26 |
Correct |
7 ms |
14040 KB |
Output is correct |
27 |
Correct |
7 ms |
14028 KB |
Output is correct |
28 |
Correct |
8 ms |
14028 KB |
Output is correct |
29 |
Correct |
7 ms |
14028 KB |
Output is correct |
30 |
Correct |
7 ms |
14004 KB |
Output is correct |
31 |
Correct |
7 ms |
14028 KB |
Output is correct |
32 |
Correct |
7 ms |
14032 KB |
Output is correct |
33 |
Correct |
8 ms |
14132 KB |
Output is correct |
34 |
Correct |
8 ms |
14132 KB |
Output is correct |
35 |
Correct |
8 ms |
14136 KB |
Output is correct |
36 |
Correct |
9 ms |
14032 KB |
Output is correct |
37 |
Correct |
8 ms |
14032 KB |
Output is correct |
38 |
Correct |
9 ms |
14032 KB |
Output is correct |
39 |
Correct |
7 ms |
14036 KB |
Output is correct |
40 |
Correct |
9 ms |
14180 KB |
Output is correct |
41 |
Correct |
8 ms |
14032 KB |
Output is correct |
42 |
Correct |
7 ms |
14032 KB |
Output is correct |
43 |
Correct |
8 ms |
14032 KB |
Output is correct |
44 |
Correct |
8 ms |
14048 KB |
Output is correct |
45 |
Correct |
8 ms |
14140 KB |
Output is correct |
46 |
Correct |
16 ms |
15748 KB |
Output is correct |
47 |
Correct |
22 ms |
16728 KB |
Output is correct |
48 |
Correct |
26 ms |
17360 KB |
Output is correct |
49 |
Correct |
28 ms |
18616 KB |
Output is correct |
50 |
Correct |
28 ms |
18924 KB |
Output is correct |
51 |
Correct |
27 ms |
17580 KB |
Output is correct |
52 |
Correct |
18 ms |
15848 KB |
Output is correct |
53 |
Correct |
17 ms |
15032 KB |
Output is correct |
54 |
Correct |
23 ms |
16676 KB |
Output is correct |
55 |
Correct |
28 ms |
18352 KB |
Output is correct |
56 |
Correct |
23 ms |
18320 KB |
Output is correct |
57 |
Correct |
20 ms |
17104 KB |
Output is correct |
58 |
Correct |
21 ms |
17616 KB |
Output is correct |
59 |
Correct |
28 ms |
18396 KB |
Output is correct |
60 |
Correct |
24 ms |
18424 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
13928 KB |
Output is correct |
2 |
Correct |
8 ms |
14000 KB |
Output is correct |
3 |
Correct |
7 ms |
13900 KB |
Output is correct |
4 |
Correct |
7 ms |
13900 KB |
Output is correct |
5 |
Correct |
7 ms |
13900 KB |
Output is correct |
6 |
Correct |
7 ms |
13900 KB |
Output is correct |
7 |
Correct |
7 ms |
13900 KB |
Output is correct |
8 |
Correct |
7 ms |
14048 KB |
Output is correct |
9 |
Correct |
8 ms |
13900 KB |
Output is correct |
10 |
Correct |
7 ms |
13940 KB |
Output is correct |
11 |
Correct |
7 ms |
13900 KB |
Output is correct |
12 |
Correct |
7 ms |
13932 KB |
Output is correct |
13 |
Correct |
7 ms |
13900 KB |
Output is correct |
14 |
Correct |
7 ms |
13900 KB |
Output is correct |
15 |
Correct |
7 ms |
13900 KB |
Output is correct |
16 |
Correct |
7 ms |
14028 KB |
Output is correct |
17 |
Correct |
8 ms |
14028 KB |
Output is correct |
18 |
Correct |
8 ms |
14044 KB |
Output is correct |
19 |
Correct |
7 ms |
13976 KB |
Output is correct |
20 |
Correct |
8 ms |
14036 KB |
Output is correct |
21 |
Correct |
7 ms |
14028 KB |
Output is correct |
22 |
Correct |
9 ms |
14028 KB |
Output is correct |
23 |
Correct |
8 ms |
14028 KB |
Output is correct |
24 |
Correct |
7 ms |
14036 KB |
Output is correct |
25 |
Correct |
7 ms |
14028 KB |
Output is correct |
26 |
Correct |
7 ms |
14040 KB |
Output is correct |
27 |
Correct |
7 ms |
14028 KB |
Output is correct |
28 |
Correct |
8 ms |
14028 KB |
Output is correct |
29 |
Correct |
7 ms |
14028 KB |
Output is correct |
30 |
Correct |
7 ms |
14004 KB |
Output is correct |
31 |
Correct |
7 ms |
14028 KB |
Output is correct |
32 |
Correct |
7 ms |
14032 KB |
Output is correct |
33 |
Correct |
8 ms |
14132 KB |
Output is correct |
34 |
Correct |
8 ms |
14132 KB |
Output is correct |
35 |
Correct |
8 ms |
14136 KB |
Output is correct |
36 |
Correct |
9 ms |
14032 KB |
Output is correct |
37 |
Correct |
8 ms |
14032 KB |
Output is correct |
38 |
Correct |
9 ms |
14032 KB |
Output is correct |
39 |
Correct |
7 ms |
14036 KB |
Output is correct |
40 |
Correct |
9 ms |
14180 KB |
Output is correct |
41 |
Correct |
8 ms |
14032 KB |
Output is correct |
42 |
Correct |
7 ms |
14032 KB |
Output is correct |
43 |
Correct |
8 ms |
14032 KB |
Output is correct |
44 |
Correct |
8 ms |
14048 KB |
Output is correct |
45 |
Correct |
8 ms |
14140 KB |
Output is correct |
46 |
Correct |
16 ms |
15748 KB |
Output is correct |
47 |
Correct |
22 ms |
16728 KB |
Output is correct |
48 |
Correct |
26 ms |
17360 KB |
Output is correct |
49 |
Correct |
28 ms |
18616 KB |
Output is correct |
50 |
Correct |
28 ms |
18924 KB |
Output is correct |
51 |
Correct |
27 ms |
17580 KB |
Output is correct |
52 |
Correct |
18 ms |
15848 KB |
Output is correct |
53 |
Correct |
17 ms |
15032 KB |
Output is correct |
54 |
Correct |
23 ms |
16676 KB |
Output is correct |
55 |
Correct |
28 ms |
18352 KB |
Output is correct |
56 |
Correct |
23 ms |
18320 KB |
Output is correct |
57 |
Correct |
20 ms |
17104 KB |
Output is correct |
58 |
Correct |
21 ms |
17616 KB |
Output is correct |
59 |
Correct |
28 ms |
18396 KB |
Output is correct |
60 |
Correct |
24 ms |
18424 KB |
Output is correct |
61 |
Correct |
55 ms |
21984 KB |
Output is correct |
62 |
Correct |
59 ms |
23704 KB |
Output is correct |
63 |
Correct |
80 ms |
27768 KB |
Output is correct |
64 |
Correct |
109 ms |
33464 KB |
Output is correct |
65 |
Correct |
106 ms |
38468 KB |
Output is correct |
66 |
Correct |
111 ms |
32232 KB |
Output is correct |
67 |
Correct |
88 ms |
28568 KB |
Output is correct |
68 |
Correct |
47 ms |
21236 KB |
Output is correct |
69 |
Correct |
93 ms |
27496 KB |
Output is correct |
70 |
Correct |
103 ms |
36292 KB |
Output is correct |
71 |
Correct |
81 ms |
35448 KB |
Output is correct |
72 |
Correct |
71 ms |
30400 KB |
Output is correct |
73 |
Correct |
82 ms |
34380 KB |
Output is correct |
74 |
Correct |
88 ms |
36820 KB |
Output is correct |
75 |
Correct |
95 ms |
36828 KB |
Output is correct |