#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair <int, int> ii;
const int N = 5e5 + 5, oo = 1e18;
int n, a[N], p[N];
set <ii> s[N];
signed main() {
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
p[i] = p[i - 1] + a[i];
}
for (int i = 1; i <= n; ++i) {
s[i].insert({1, 1});
if (i == n) {
cout << (*(s[i].rbegin())).first << endl;
return 0;
}
int lst = oo;
while (!s[i].empty()) {
ii mx = *s[i].rbegin();
s[i].erase(mx);
if (mx.first == lst) continue;
s[i + 1].insert(mx);
int l = i + 1, r = n, ans = -1;
int sum = p[i] - p[mx.second - 1];
while (l <= r) {
int mid = (l + r) >> 1;
if (p[mid] - p[i] >= sum) {
r = mid - 1;
ans = mid;
} else l = mid + 1;
}
if (~ans) s[ans].insert({mx.first + 1, i + 1});
if (lst != oo) break;
lst = mx.first;
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
23808 KB |
Output is correct |
2 |
Correct |
19 ms |
23808 KB |
Output is correct |
3 |
Correct |
14 ms |
23808 KB |
Output is correct |
4 |
Correct |
19 ms |
23808 KB |
Output is correct |
5 |
Correct |
19 ms |
23808 KB |
Output is correct |
6 |
Correct |
14 ms |
23808 KB |
Output is correct |
7 |
Correct |
14 ms |
23808 KB |
Output is correct |
8 |
Correct |
14 ms |
23808 KB |
Output is correct |
9 |
Correct |
14 ms |
23808 KB |
Output is correct |
10 |
Correct |
14 ms |
23808 KB |
Output is correct |
11 |
Correct |
14 ms |
23808 KB |
Output is correct |
12 |
Correct |
14 ms |
23808 KB |
Output is correct |
13 |
Correct |
14 ms |
23808 KB |
Output is correct |
14 |
Correct |
17 ms |
23808 KB |
Output is correct |
15 |
Correct |
14 ms |
23808 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
23808 KB |
Output is correct |
2 |
Correct |
19 ms |
23808 KB |
Output is correct |
3 |
Correct |
14 ms |
23808 KB |
Output is correct |
4 |
Correct |
19 ms |
23808 KB |
Output is correct |
5 |
Correct |
19 ms |
23808 KB |
Output is correct |
6 |
Correct |
14 ms |
23808 KB |
Output is correct |
7 |
Correct |
14 ms |
23808 KB |
Output is correct |
8 |
Correct |
14 ms |
23808 KB |
Output is correct |
9 |
Correct |
14 ms |
23808 KB |
Output is correct |
10 |
Correct |
14 ms |
23808 KB |
Output is correct |
11 |
Correct |
14 ms |
23808 KB |
Output is correct |
12 |
Correct |
14 ms |
23808 KB |
Output is correct |
13 |
Correct |
14 ms |
23808 KB |
Output is correct |
14 |
Correct |
17 ms |
23808 KB |
Output is correct |
15 |
Correct |
14 ms |
23808 KB |
Output is correct |
16 |
Correct |
14 ms |
23808 KB |
Output is correct |
17 |
Correct |
16 ms |
23936 KB |
Output is correct |
18 |
Correct |
18 ms |
23936 KB |
Output is correct |
19 |
Correct |
14 ms |
23936 KB |
Output is correct |
20 |
Correct |
15 ms |
23936 KB |
Output is correct |
21 |
Correct |
15 ms |
23936 KB |
Output is correct |
22 |
Correct |
15 ms |
23936 KB |
Output is correct |
23 |
Correct |
16 ms |
23936 KB |
Output is correct |
24 |
Correct |
18 ms |
23936 KB |
Output is correct |
25 |
Correct |
14 ms |
23936 KB |
Output is correct |
26 |
Correct |
14 ms |
23936 KB |
Output is correct |
27 |
Correct |
14 ms |
23936 KB |
Output is correct |
28 |
Correct |
14 ms |
23936 KB |
Output is correct |
29 |
Correct |
14 ms |
23936 KB |
Output is correct |
30 |
Correct |
16 ms |
24064 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
23808 KB |
Output is correct |
2 |
Correct |
19 ms |
23808 KB |
Output is correct |
3 |
Correct |
14 ms |
23808 KB |
Output is correct |
4 |
Correct |
19 ms |
23808 KB |
Output is correct |
5 |
Correct |
19 ms |
23808 KB |
Output is correct |
6 |
Correct |
14 ms |
23808 KB |
Output is correct |
7 |
Correct |
14 ms |
23808 KB |
Output is correct |
8 |
Correct |
14 ms |
23808 KB |
Output is correct |
9 |
Correct |
14 ms |
23808 KB |
Output is correct |
10 |
Correct |
14 ms |
23808 KB |
Output is correct |
11 |
Correct |
14 ms |
23808 KB |
Output is correct |
12 |
Correct |
14 ms |
23808 KB |
Output is correct |
13 |
Correct |
14 ms |
23808 KB |
Output is correct |
14 |
Correct |
17 ms |
23808 KB |
Output is correct |
15 |
Correct |
14 ms |
23808 KB |
Output is correct |
16 |
Correct |
14 ms |
23808 KB |
Output is correct |
17 |
Correct |
16 ms |
23936 KB |
Output is correct |
18 |
Correct |
18 ms |
23936 KB |
Output is correct |
19 |
Correct |
14 ms |
23936 KB |
Output is correct |
20 |
Correct |
15 ms |
23936 KB |
Output is correct |
21 |
Correct |
15 ms |
23936 KB |
Output is correct |
22 |
Correct |
15 ms |
23936 KB |
Output is correct |
23 |
Correct |
16 ms |
23936 KB |
Output is correct |
24 |
Correct |
18 ms |
23936 KB |
Output is correct |
25 |
Correct |
14 ms |
23936 KB |
Output is correct |
26 |
Correct |
14 ms |
23936 KB |
Output is correct |
27 |
Correct |
14 ms |
23936 KB |
Output is correct |
28 |
Correct |
14 ms |
23936 KB |
Output is correct |
29 |
Correct |
14 ms |
23936 KB |
Output is correct |
30 |
Correct |
16 ms |
24064 KB |
Output is correct |
31 |
Correct |
14 ms |
23936 KB |
Output is correct |
32 |
Correct |
16 ms |
24192 KB |
Output is correct |
33 |
Correct |
19 ms |
24496 KB |
Output is correct |
34 |
Correct |
15 ms |
24320 KB |
Output is correct |
35 |
Correct |
16 ms |
24448 KB |
Output is correct |
36 |
Correct |
17 ms |
24320 KB |
Output is correct |
37 |
Correct |
16 ms |
24192 KB |
Output is correct |
38 |
Correct |
15 ms |
24192 KB |
Output is correct |
39 |
Correct |
17 ms |
24320 KB |
Output is correct |
40 |
Correct |
16 ms |
24320 KB |
Output is correct |
41 |
Correct |
16 ms |
24448 KB |
Output is correct |
42 |
Correct |
16 ms |
24448 KB |
Output is correct |
43 |
Correct |
16 ms |
24320 KB |
Output is correct |
44 |
Correct |
15 ms |
24448 KB |
Output is correct |
45 |
Correct |
16 ms |
24448 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
23808 KB |
Output is correct |
2 |
Correct |
19 ms |
23808 KB |
Output is correct |
3 |
Correct |
14 ms |
23808 KB |
Output is correct |
4 |
Correct |
19 ms |
23808 KB |
Output is correct |
5 |
Correct |
19 ms |
23808 KB |
Output is correct |
6 |
Correct |
14 ms |
23808 KB |
Output is correct |
7 |
Correct |
14 ms |
23808 KB |
Output is correct |
8 |
Correct |
14 ms |
23808 KB |
Output is correct |
9 |
Correct |
14 ms |
23808 KB |
Output is correct |
10 |
Correct |
14 ms |
23808 KB |
Output is correct |
11 |
Correct |
14 ms |
23808 KB |
Output is correct |
12 |
Correct |
14 ms |
23808 KB |
Output is correct |
13 |
Correct |
14 ms |
23808 KB |
Output is correct |
14 |
Correct |
17 ms |
23808 KB |
Output is correct |
15 |
Correct |
14 ms |
23808 KB |
Output is correct |
16 |
Correct |
14 ms |
23808 KB |
Output is correct |
17 |
Correct |
16 ms |
23936 KB |
Output is correct |
18 |
Correct |
18 ms |
23936 KB |
Output is correct |
19 |
Correct |
14 ms |
23936 KB |
Output is correct |
20 |
Correct |
15 ms |
23936 KB |
Output is correct |
21 |
Correct |
15 ms |
23936 KB |
Output is correct |
22 |
Correct |
15 ms |
23936 KB |
Output is correct |
23 |
Correct |
16 ms |
23936 KB |
Output is correct |
24 |
Correct |
18 ms |
23936 KB |
Output is correct |
25 |
Correct |
14 ms |
23936 KB |
Output is correct |
26 |
Correct |
14 ms |
23936 KB |
Output is correct |
27 |
Correct |
14 ms |
23936 KB |
Output is correct |
28 |
Correct |
14 ms |
23936 KB |
Output is correct |
29 |
Correct |
14 ms |
23936 KB |
Output is correct |
30 |
Correct |
16 ms |
24064 KB |
Output is correct |
31 |
Correct |
14 ms |
23936 KB |
Output is correct |
32 |
Correct |
16 ms |
24192 KB |
Output is correct |
33 |
Correct |
19 ms |
24496 KB |
Output is correct |
34 |
Correct |
15 ms |
24320 KB |
Output is correct |
35 |
Correct |
16 ms |
24448 KB |
Output is correct |
36 |
Correct |
17 ms |
24320 KB |
Output is correct |
37 |
Correct |
16 ms |
24192 KB |
Output is correct |
38 |
Correct |
15 ms |
24192 KB |
Output is correct |
39 |
Correct |
17 ms |
24320 KB |
Output is correct |
40 |
Correct |
16 ms |
24320 KB |
Output is correct |
41 |
Correct |
16 ms |
24448 KB |
Output is correct |
42 |
Correct |
16 ms |
24448 KB |
Output is correct |
43 |
Correct |
16 ms |
24320 KB |
Output is correct |
44 |
Correct |
15 ms |
24448 KB |
Output is correct |
45 |
Correct |
16 ms |
24448 KB |
Output is correct |
46 |
Correct |
29 ms |
25856 KB |
Output is correct |
47 |
Correct |
86 ms |
37808 KB |
Output is correct |
48 |
Correct |
89 ms |
44664 KB |
Output is correct |
49 |
Correct |
79 ms |
43900 KB |
Output is correct |
50 |
Correct |
75 ms |
45248 KB |
Output is correct |
51 |
Correct |
89 ms |
39032 KB |
Output is correct |
52 |
Correct |
53 ms |
31480 KB |
Output is correct |
53 |
Correct |
37 ms |
28408 KB |
Output is correct |
54 |
Correct |
85 ms |
38264 KB |
Output is correct |
55 |
Correct |
83 ms |
39032 KB |
Output is correct |
56 |
Correct |
69 ms |
44664 KB |
Output is correct |
57 |
Correct |
85 ms |
44644 KB |
Output is correct |
58 |
Correct |
80 ms |
43384 KB |
Output is correct |
59 |
Correct |
71 ms |
44924 KB |
Output is correct |
60 |
Correct |
76 ms |
40952 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
23808 KB |
Output is correct |
2 |
Correct |
19 ms |
23808 KB |
Output is correct |
3 |
Correct |
14 ms |
23808 KB |
Output is correct |
4 |
Correct |
19 ms |
23808 KB |
Output is correct |
5 |
Correct |
19 ms |
23808 KB |
Output is correct |
6 |
Correct |
14 ms |
23808 KB |
Output is correct |
7 |
Correct |
14 ms |
23808 KB |
Output is correct |
8 |
Correct |
14 ms |
23808 KB |
Output is correct |
9 |
Correct |
14 ms |
23808 KB |
Output is correct |
10 |
Correct |
14 ms |
23808 KB |
Output is correct |
11 |
Correct |
14 ms |
23808 KB |
Output is correct |
12 |
Correct |
14 ms |
23808 KB |
Output is correct |
13 |
Correct |
14 ms |
23808 KB |
Output is correct |
14 |
Correct |
17 ms |
23808 KB |
Output is correct |
15 |
Correct |
14 ms |
23808 KB |
Output is correct |
16 |
Correct |
14 ms |
23808 KB |
Output is correct |
17 |
Correct |
16 ms |
23936 KB |
Output is correct |
18 |
Correct |
18 ms |
23936 KB |
Output is correct |
19 |
Correct |
14 ms |
23936 KB |
Output is correct |
20 |
Correct |
15 ms |
23936 KB |
Output is correct |
21 |
Correct |
15 ms |
23936 KB |
Output is correct |
22 |
Correct |
15 ms |
23936 KB |
Output is correct |
23 |
Correct |
16 ms |
23936 KB |
Output is correct |
24 |
Correct |
18 ms |
23936 KB |
Output is correct |
25 |
Correct |
14 ms |
23936 KB |
Output is correct |
26 |
Correct |
14 ms |
23936 KB |
Output is correct |
27 |
Correct |
14 ms |
23936 KB |
Output is correct |
28 |
Correct |
14 ms |
23936 KB |
Output is correct |
29 |
Correct |
14 ms |
23936 KB |
Output is correct |
30 |
Correct |
16 ms |
24064 KB |
Output is correct |
31 |
Correct |
14 ms |
23936 KB |
Output is correct |
32 |
Correct |
16 ms |
24192 KB |
Output is correct |
33 |
Correct |
19 ms |
24496 KB |
Output is correct |
34 |
Correct |
15 ms |
24320 KB |
Output is correct |
35 |
Correct |
16 ms |
24448 KB |
Output is correct |
36 |
Correct |
17 ms |
24320 KB |
Output is correct |
37 |
Correct |
16 ms |
24192 KB |
Output is correct |
38 |
Correct |
15 ms |
24192 KB |
Output is correct |
39 |
Correct |
17 ms |
24320 KB |
Output is correct |
40 |
Correct |
16 ms |
24320 KB |
Output is correct |
41 |
Correct |
16 ms |
24448 KB |
Output is correct |
42 |
Correct |
16 ms |
24448 KB |
Output is correct |
43 |
Correct |
16 ms |
24320 KB |
Output is correct |
44 |
Correct |
15 ms |
24448 KB |
Output is correct |
45 |
Correct |
16 ms |
24448 KB |
Output is correct |
46 |
Correct |
29 ms |
25856 KB |
Output is correct |
47 |
Correct |
86 ms |
37808 KB |
Output is correct |
48 |
Correct |
89 ms |
44664 KB |
Output is correct |
49 |
Correct |
79 ms |
43900 KB |
Output is correct |
50 |
Correct |
75 ms |
45248 KB |
Output is correct |
51 |
Correct |
89 ms |
39032 KB |
Output is correct |
52 |
Correct |
53 ms |
31480 KB |
Output is correct |
53 |
Correct |
37 ms |
28408 KB |
Output is correct |
54 |
Correct |
85 ms |
38264 KB |
Output is correct |
55 |
Correct |
83 ms |
39032 KB |
Output is correct |
56 |
Correct |
69 ms |
44664 KB |
Output is correct |
57 |
Correct |
85 ms |
44644 KB |
Output is correct |
58 |
Correct |
80 ms |
43384 KB |
Output is correct |
59 |
Correct |
71 ms |
44924 KB |
Output is correct |
60 |
Correct |
76 ms |
40952 KB |
Output is correct |
61 |
Correct |
103 ms |
33660 KB |
Output is correct |
62 |
Correct |
219 ms |
49316 KB |
Output is correct |
63 |
Correct |
391 ms |
83192 KB |
Output is correct |
64 |
Correct |
380 ms |
130296 KB |
Output is correct |
65 |
Correct |
323 ms |
130424 KB |
Output is correct |
66 |
Correct |
407 ms |
99576 KB |
Output is correct |
67 |
Correct |
326 ms |
84344 KB |
Output is correct |
68 |
Correct |
174 ms |
54264 KB |
Output is correct |
69 |
Correct |
383 ms |
95868 KB |
Output is correct |
70 |
Correct |
335 ms |
99576 KB |
Output is correct |
71 |
Correct |
279 ms |
127480 KB |
Output is correct |
72 |
Correct |
382 ms |
127864 KB |
Output is correct |
73 |
Correct |
329 ms |
128504 KB |
Output is correct |
74 |
Correct |
283 ms |
128888 KB |
Output is correct |
75 |
Correct |
294 ms |
122232 KB |
Output is correct |