#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});
lst = mx.first;
if (lst != oo) break;
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
27228 KB |
Output is correct |
2 |
Correct |
5 ms |
27228 KB |
Output is correct |
3 |
Correct |
6 ms |
27240 KB |
Output is correct |
4 |
Correct |
8 ms |
27260 KB |
Output is correct |
5 |
Correct |
5 ms |
27228 KB |
Output is correct |
6 |
Correct |
6 ms |
27228 KB |
Output is correct |
7 |
Correct |
7 ms |
27380 KB |
Output is correct |
8 |
Correct |
5 ms |
27228 KB |
Output is correct |
9 |
Correct |
5 ms |
27228 KB |
Output is correct |
10 |
Correct |
5 ms |
27228 KB |
Output is correct |
11 |
Correct |
7 ms |
27228 KB |
Output is correct |
12 |
Correct |
5 ms |
27228 KB |
Output is correct |
13 |
Correct |
6 ms |
27256 KB |
Output is correct |
14 |
Correct |
5 ms |
27228 KB |
Output is correct |
15 |
Correct |
6 ms |
27228 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
27228 KB |
Output is correct |
2 |
Correct |
5 ms |
27228 KB |
Output is correct |
3 |
Correct |
6 ms |
27240 KB |
Output is correct |
4 |
Correct |
8 ms |
27260 KB |
Output is correct |
5 |
Correct |
5 ms |
27228 KB |
Output is correct |
6 |
Correct |
6 ms |
27228 KB |
Output is correct |
7 |
Correct |
7 ms |
27380 KB |
Output is correct |
8 |
Correct |
5 ms |
27228 KB |
Output is correct |
9 |
Correct |
5 ms |
27228 KB |
Output is correct |
10 |
Correct |
5 ms |
27228 KB |
Output is correct |
11 |
Correct |
7 ms |
27228 KB |
Output is correct |
12 |
Correct |
5 ms |
27228 KB |
Output is correct |
13 |
Correct |
6 ms |
27256 KB |
Output is correct |
14 |
Correct |
5 ms |
27228 KB |
Output is correct |
15 |
Correct |
6 ms |
27228 KB |
Output is correct |
16 |
Correct |
7 ms |
27484 KB |
Output is correct |
17 |
Correct |
5 ms |
27480 KB |
Output is correct |
18 |
Correct |
5 ms |
27228 KB |
Output is correct |
19 |
Correct |
7 ms |
27228 KB |
Output is correct |
20 |
Correct |
6 ms |
27260 KB |
Output is correct |
21 |
Correct |
6 ms |
27224 KB |
Output is correct |
22 |
Correct |
6 ms |
27224 KB |
Output is correct |
23 |
Correct |
6 ms |
27224 KB |
Output is correct |
24 |
Correct |
6 ms |
27228 KB |
Output is correct |
25 |
Correct |
6 ms |
27228 KB |
Output is correct |
26 |
Correct |
6 ms |
27236 KB |
Output is correct |
27 |
Correct |
7 ms |
27480 KB |
Output is correct |
28 |
Correct |
5 ms |
27228 KB |
Output is correct |
29 |
Correct |
5 ms |
27228 KB |
Output is correct |
30 |
Correct |
5 ms |
27228 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
27228 KB |
Output is correct |
2 |
Correct |
5 ms |
27228 KB |
Output is correct |
3 |
Correct |
6 ms |
27240 KB |
Output is correct |
4 |
Correct |
8 ms |
27260 KB |
Output is correct |
5 |
Correct |
5 ms |
27228 KB |
Output is correct |
6 |
Correct |
6 ms |
27228 KB |
Output is correct |
7 |
Correct |
7 ms |
27380 KB |
Output is correct |
8 |
Correct |
5 ms |
27228 KB |
Output is correct |
9 |
Correct |
5 ms |
27228 KB |
Output is correct |
10 |
Correct |
5 ms |
27228 KB |
Output is correct |
11 |
Correct |
7 ms |
27228 KB |
Output is correct |
12 |
Correct |
5 ms |
27228 KB |
Output is correct |
13 |
Correct |
6 ms |
27256 KB |
Output is correct |
14 |
Correct |
5 ms |
27228 KB |
Output is correct |
15 |
Correct |
6 ms |
27228 KB |
Output is correct |
16 |
Correct |
7 ms |
27484 KB |
Output is correct |
17 |
Correct |
5 ms |
27480 KB |
Output is correct |
18 |
Correct |
5 ms |
27228 KB |
Output is correct |
19 |
Correct |
7 ms |
27228 KB |
Output is correct |
20 |
Correct |
6 ms |
27260 KB |
Output is correct |
21 |
Correct |
6 ms |
27224 KB |
Output is correct |
22 |
Correct |
6 ms |
27224 KB |
Output is correct |
23 |
Correct |
6 ms |
27224 KB |
Output is correct |
24 |
Correct |
6 ms |
27228 KB |
Output is correct |
25 |
Correct |
6 ms |
27228 KB |
Output is correct |
26 |
Correct |
6 ms |
27236 KB |
Output is correct |
27 |
Correct |
7 ms |
27480 KB |
Output is correct |
28 |
Correct |
5 ms |
27228 KB |
Output is correct |
29 |
Correct |
5 ms |
27228 KB |
Output is correct |
30 |
Correct |
5 ms |
27228 KB |
Output is correct |
31 |
Correct |
7 ms |
27136 KB |
Output is correct |
32 |
Correct |
8 ms |
27484 KB |
Output is correct |
33 |
Correct |
6 ms |
27580 KB |
Output is correct |
34 |
Correct |
6 ms |
27596 KB |
Output is correct |
35 |
Correct |
6 ms |
27484 KB |
Output is correct |
36 |
Correct |
7 ms |
27484 KB |
Output is correct |
37 |
Correct |
6 ms |
27504 KB |
Output is correct |
38 |
Correct |
6 ms |
27580 KB |
Output is correct |
39 |
Correct |
6 ms |
27516 KB |
Output is correct |
40 |
Correct |
7 ms |
27736 KB |
Output is correct |
41 |
Correct |
7 ms |
27484 KB |
Output is correct |
42 |
Correct |
7 ms |
27996 KB |
Output is correct |
43 |
Correct |
6 ms |
27528 KB |
Output is correct |
44 |
Correct |
7 ms |
27484 KB |
Output is correct |
45 |
Correct |
6 ms |
27576 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
27228 KB |
Output is correct |
2 |
Correct |
5 ms |
27228 KB |
Output is correct |
3 |
Correct |
6 ms |
27240 KB |
Output is correct |
4 |
Correct |
8 ms |
27260 KB |
Output is correct |
5 |
Correct |
5 ms |
27228 KB |
Output is correct |
6 |
Correct |
6 ms |
27228 KB |
Output is correct |
7 |
Correct |
7 ms |
27380 KB |
Output is correct |
8 |
Correct |
5 ms |
27228 KB |
Output is correct |
9 |
Correct |
5 ms |
27228 KB |
Output is correct |
10 |
Correct |
5 ms |
27228 KB |
Output is correct |
11 |
Correct |
7 ms |
27228 KB |
Output is correct |
12 |
Correct |
5 ms |
27228 KB |
Output is correct |
13 |
Correct |
6 ms |
27256 KB |
Output is correct |
14 |
Correct |
5 ms |
27228 KB |
Output is correct |
15 |
Correct |
6 ms |
27228 KB |
Output is correct |
16 |
Correct |
7 ms |
27484 KB |
Output is correct |
17 |
Correct |
5 ms |
27480 KB |
Output is correct |
18 |
Correct |
5 ms |
27228 KB |
Output is correct |
19 |
Correct |
7 ms |
27228 KB |
Output is correct |
20 |
Correct |
6 ms |
27260 KB |
Output is correct |
21 |
Correct |
6 ms |
27224 KB |
Output is correct |
22 |
Correct |
6 ms |
27224 KB |
Output is correct |
23 |
Correct |
6 ms |
27224 KB |
Output is correct |
24 |
Correct |
6 ms |
27228 KB |
Output is correct |
25 |
Correct |
6 ms |
27228 KB |
Output is correct |
26 |
Correct |
6 ms |
27236 KB |
Output is correct |
27 |
Correct |
7 ms |
27480 KB |
Output is correct |
28 |
Correct |
5 ms |
27228 KB |
Output is correct |
29 |
Correct |
5 ms |
27228 KB |
Output is correct |
30 |
Correct |
5 ms |
27228 KB |
Output is correct |
31 |
Correct |
7 ms |
27136 KB |
Output is correct |
32 |
Correct |
8 ms |
27484 KB |
Output is correct |
33 |
Correct |
6 ms |
27580 KB |
Output is correct |
34 |
Correct |
6 ms |
27596 KB |
Output is correct |
35 |
Correct |
6 ms |
27484 KB |
Output is correct |
36 |
Correct |
7 ms |
27484 KB |
Output is correct |
37 |
Correct |
6 ms |
27504 KB |
Output is correct |
38 |
Correct |
6 ms |
27580 KB |
Output is correct |
39 |
Correct |
6 ms |
27516 KB |
Output is correct |
40 |
Correct |
7 ms |
27736 KB |
Output is correct |
41 |
Correct |
7 ms |
27484 KB |
Output is correct |
42 |
Correct |
7 ms |
27996 KB |
Output is correct |
43 |
Correct |
6 ms |
27528 KB |
Output is correct |
44 |
Correct |
7 ms |
27484 KB |
Output is correct |
45 |
Correct |
6 ms |
27576 KB |
Output is correct |
46 |
Correct |
15 ms |
27484 KB |
Output is correct |
47 |
Correct |
36 ms |
39752 KB |
Output is correct |
48 |
Correct |
37 ms |
40276 KB |
Output is correct |
49 |
Correct |
31 ms |
40020 KB |
Output is correct |
50 |
Correct |
33 ms |
40796 KB |
Output is correct |
51 |
Correct |
39 ms |
40536 KB |
Output is correct |
52 |
Correct |
21 ms |
33876 KB |
Output is correct |
53 |
Correct |
15 ms |
31320 KB |
Output is correct |
54 |
Correct |
34 ms |
40028 KB |
Output is correct |
55 |
Correct |
34 ms |
40728 KB |
Output is correct |
56 |
Correct |
29 ms |
40284 KB |
Output is correct |
57 |
Correct |
35 ms |
40024 KB |
Output is correct |
58 |
Correct |
32 ms |
40284 KB |
Output is correct |
59 |
Correct |
29 ms |
40152 KB |
Output is correct |
60 |
Correct |
30 ms |
40576 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
27228 KB |
Output is correct |
2 |
Correct |
5 ms |
27228 KB |
Output is correct |
3 |
Correct |
6 ms |
27240 KB |
Output is correct |
4 |
Correct |
8 ms |
27260 KB |
Output is correct |
5 |
Correct |
5 ms |
27228 KB |
Output is correct |
6 |
Correct |
6 ms |
27228 KB |
Output is correct |
7 |
Correct |
7 ms |
27380 KB |
Output is correct |
8 |
Correct |
5 ms |
27228 KB |
Output is correct |
9 |
Correct |
5 ms |
27228 KB |
Output is correct |
10 |
Correct |
5 ms |
27228 KB |
Output is correct |
11 |
Correct |
7 ms |
27228 KB |
Output is correct |
12 |
Correct |
5 ms |
27228 KB |
Output is correct |
13 |
Correct |
6 ms |
27256 KB |
Output is correct |
14 |
Correct |
5 ms |
27228 KB |
Output is correct |
15 |
Correct |
6 ms |
27228 KB |
Output is correct |
16 |
Correct |
7 ms |
27484 KB |
Output is correct |
17 |
Correct |
5 ms |
27480 KB |
Output is correct |
18 |
Correct |
5 ms |
27228 KB |
Output is correct |
19 |
Correct |
7 ms |
27228 KB |
Output is correct |
20 |
Correct |
6 ms |
27260 KB |
Output is correct |
21 |
Correct |
6 ms |
27224 KB |
Output is correct |
22 |
Correct |
6 ms |
27224 KB |
Output is correct |
23 |
Correct |
6 ms |
27224 KB |
Output is correct |
24 |
Correct |
6 ms |
27228 KB |
Output is correct |
25 |
Correct |
6 ms |
27228 KB |
Output is correct |
26 |
Correct |
6 ms |
27236 KB |
Output is correct |
27 |
Correct |
7 ms |
27480 KB |
Output is correct |
28 |
Correct |
5 ms |
27228 KB |
Output is correct |
29 |
Correct |
5 ms |
27228 KB |
Output is correct |
30 |
Correct |
5 ms |
27228 KB |
Output is correct |
31 |
Correct |
7 ms |
27136 KB |
Output is correct |
32 |
Correct |
8 ms |
27484 KB |
Output is correct |
33 |
Correct |
6 ms |
27580 KB |
Output is correct |
34 |
Correct |
6 ms |
27596 KB |
Output is correct |
35 |
Correct |
6 ms |
27484 KB |
Output is correct |
36 |
Correct |
7 ms |
27484 KB |
Output is correct |
37 |
Correct |
6 ms |
27504 KB |
Output is correct |
38 |
Correct |
6 ms |
27580 KB |
Output is correct |
39 |
Correct |
6 ms |
27516 KB |
Output is correct |
40 |
Correct |
7 ms |
27736 KB |
Output is correct |
41 |
Correct |
7 ms |
27484 KB |
Output is correct |
42 |
Correct |
7 ms |
27996 KB |
Output is correct |
43 |
Correct |
6 ms |
27528 KB |
Output is correct |
44 |
Correct |
7 ms |
27484 KB |
Output is correct |
45 |
Correct |
6 ms |
27576 KB |
Output is correct |
46 |
Correct |
15 ms |
27484 KB |
Output is correct |
47 |
Correct |
36 ms |
39752 KB |
Output is correct |
48 |
Correct |
37 ms |
40276 KB |
Output is correct |
49 |
Correct |
31 ms |
40020 KB |
Output is correct |
50 |
Correct |
33 ms |
40796 KB |
Output is correct |
51 |
Correct |
39 ms |
40536 KB |
Output is correct |
52 |
Correct |
21 ms |
33876 KB |
Output is correct |
53 |
Correct |
15 ms |
31320 KB |
Output is correct |
54 |
Correct |
34 ms |
40028 KB |
Output is correct |
55 |
Correct |
34 ms |
40728 KB |
Output is correct |
56 |
Correct |
29 ms |
40284 KB |
Output is correct |
57 |
Correct |
35 ms |
40024 KB |
Output is correct |
58 |
Correct |
32 ms |
40284 KB |
Output is correct |
59 |
Correct |
29 ms |
40152 KB |
Output is correct |
60 |
Correct |
30 ms |
40576 KB |
Output is correct |
61 |
Correct |
53 ms |
33584 KB |
Output is correct |
62 |
Correct |
120 ms |
64852 KB |
Output is correct |
63 |
Correct |
169 ms |
90524 KB |
Output is correct |
64 |
Correct |
159 ms |
98912 KB |
Output is correct |
65 |
Correct |
143 ms |
99200 KB |
Output is correct |
66 |
Correct |
171 ms |
99108 KB |
Output is correct |
67 |
Correct |
138 ms |
85076 KB |
Output is correct |
68 |
Correct |
71 ms |
58176 KB |
Output is correct |
69 |
Correct |
156 ms |
95284 KB |
Output is correct |
70 |
Correct |
160 ms |
99208 KB |
Output is correct |
71 |
Correct |
124 ms |
96084 KB |
Output is correct |
72 |
Correct |
168 ms |
96796 KB |
Output is correct |
73 |
Correct |
139 ms |
97204 KB |
Output is correct |
74 |
Correct |
132 ms |
97620 KB |
Output is correct |
75 |
Correct |
137 ms |
97620 KB |
Output is correct |