#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define N 2000001
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll INF = 1e18, MOD = 1e9 + 7, MOD2 = 1e6 + 3;
ll d_m[N], d[N], p[N], a[N], n;
int main () {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
p[i] = a[i] + (i ? p[i-1] : 0);
}
memset (d_m, -1, sizeof (d_m));
for (int i = 0; i < n; i++) {
if (i) d_m[i] = max (d_m[i], d_m[i-1]);
d[i] = (d_m[i] >= 0 ? d[d_m[i]] : 0) + 1;
int l = i + 1, r = n;
while (l < r) {
int mid = (l + r) / 2;
if (p[i] - p[d_m[i]] <= p[mid] - p[i]) r = mid;
else l = mid + 1;
}
d_m[l] = max (d_m[l], (ll)i);
}
cout << d[n-1];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
15992 KB |
Output is correct |
2 |
Correct |
13 ms |
15992 KB |
Output is correct |
3 |
Correct |
13 ms |
15992 KB |
Output is correct |
4 |
Correct |
13 ms |
15992 KB |
Output is correct |
5 |
Correct |
13 ms |
15992 KB |
Output is correct |
6 |
Correct |
13 ms |
15992 KB |
Output is correct |
7 |
Correct |
13 ms |
15992 KB |
Output is correct |
8 |
Correct |
13 ms |
15996 KB |
Output is correct |
9 |
Correct |
13 ms |
15992 KB |
Output is correct |
10 |
Correct |
13 ms |
15992 KB |
Output is correct |
11 |
Correct |
13 ms |
15992 KB |
Output is correct |
12 |
Correct |
13 ms |
15992 KB |
Output is correct |
13 |
Correct |
13 ms |
15992 KB |
Output is correct |
14 |
Correct |
13 ms |
15992 KB |
Output is correct |
15 |
Correct |
13 ms |
15992 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
15992 KB |
Output is correct |
2 |
Correct |
13 ms |
15992 KB |
Output is correct |
3 |
Correct |
13 ms |
15992 KB |
Output is correct |
4 |
Correct |
13 ms |
15992 KB |
Output is correct |
5 |
Correct |
13 ms |
15992 KB |
Output is correct |
6 |
Correct |
13 ms |
15992 KB |
Output is correct |
7 |
Correct |
13 ms |
15992 KB |
Output is correct |
8 |
Correct |
13 ms |
15996 KB |
Output is correct |
9 |
Correct |
13 ms |
15992 KB |
Output is correct |
10 |
Correct |
13 ms |
15992 KB |
Output is correct |
11 |
Correct |
13 ms |
15992 KB |
Output is correct |
12 |
Correct |
13 ms |
15992 KB |
Output is correct |
13 |
Correct |
13 ms |
15992 KB |
Output is correct |
14 |
Correct |
13 ms |
15992 KB |
Output is correct |
15 |
Correct |
13 ms |
15992 KB |
Output is correct |
16 |
Correct |
13 ms |
15992 KB |
Output is correct |
17 |
Correct |
14 ms |
15992 KB |
Output is correct |
18 |
Correct |
13 ms |
15992 KB |
Output is correct |
19 |
Correct |
13 ms |
15992 KB |
Output is correct |
20 |
Correct |
13 ms |
15992 KB |
Output is correct |
21 |
Correct |
13 ms |
15992 KB |
Output is correct |
22 |
Correct |
13 ms |
15992 KB |
Output is correct |
23 |
Correct |
13 ms |
15992 KB |
Output is correct |
24 |
Correct |
14 ms |
15992 KB |
Output is correct |
25 |
Correct |
13 ms |
15996 KB |
Output is correct |
26 |
Correct |
14 ms |
15992 KB |
Output is correct |
27 |
Correct |
13 ms |
15996 KB |
Output is correct |
28 |
Correct |
13 ms |
15992 KB |
Output is correct |
29 |
Correct |
13 ms |
15992 KB |
Output is correct |
30 |
Correct |
13 ms |
15992 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
15992 KB |
Output is correct |
2 |
Correct |
13 ms |
15992 KB |
Output is correct |
3 |
Correct |
13 ms |
15992 KB |
Output is correct |
4 |
Correct |
13 ms |
15992 KB |
Output is correct |
5 |
Correct |
13 ms |
15992 KB |
Output is correct |
6 |
Correct |
13 ms |
15992 KB |
Output is correct |
7 |
Correct |
13 ms |
15992 KB |
Output is correct |
8 |
Correct |
13 ms |
15996 KB |
Output is correct |
9 |
Correct |
13 ms |
15992 KB |
Output is correct |
10 |
Correct |
13 ms |
15992 KB |
Output is correct |
11 |
Correct |
13 ms |
15992 KB |
Output is correct |
12 |
Correct |
13 ms |
15992 KB |
Output is correct |
13 |
Correct |
13 ms |
15992 KB |
Output is correct |
14 |
Correct |
13 ms |
15992 KB |
Output is correct |
15 |
Correct |
13 ms |
15992 KB |
Output is correct |
16 |
Correct |
13 ms |
15992 KB |
Output is correct |
17 |
Correct |
14 ms |
15992 KB |
Output is correct |
18 |
Correct |
13 ms |
15992 KB |
Output is correct |
19 |
Correct |
13 ms |
15992 KB |
Output is correct |
20 |
Correct |
13 ms |
15992 KB |
Output is correct |
21 |
Correct |
13 ms |
15992 KB |
Output is correct |
22 |
Correct |
13 ms |
15992 KB |
Output is correct |
23 |
Correct |
13 ms |
15992 KB |
Output is correct |
24 |
Correct |
14 ms |
15992 KB |
Output is correct |
25 |
Correct |
13 ms |
15996 KB |
Output is correct |
26 |
Correct |
14 ms |
15992 KB |
Output is correct |
27 |
Correct |
13 ms |
15996 KB |
Output is correct |
28 |
Correct |
13 ms |
15992 KB |
Output is correct |
29 |
Correct |
13 ms |
15992 KB |
Output is correct |
30 |
Correct |
13 ms |
15992 KB |
Output is correct |
31 |
Correct |
14 ms |
16120 KB |
Output is correct |
32 |
Correct |
15 ms |
16120 KB |
Output is correct |
33 |
Correct |
15 ms |
16120 KB |
Output is correct |
34 |
Correct |
15 ms |
16120 KB |
Output is correct |
35 |
Correct |
14 ms |
16120 KB |
Output is correct |
36 |
Correct |
15 ms |
16120 KB |
Output is correct |
37 |
Correct |
14 ms |
16120 KB |
Output is correct |
38 |
Correct |
15 ms |
15992 KB |
Output is correct |
39 |
Correct |
14 ms |
16120 KB |
Output is correct |
40 |
Correct |
15 ms |
16124 KB |
Output is correct |
41 |
Correct |
14 ms |
15992 KB |
Output is correct |
42 |
Correct |
14 ms |
16120 KB |
Output is correct |
43 |
Correct |
14 ms |
16120 KB |
Output is correct |
44 |
Correct |
14 ms |
16120 KB |
Output is correct |
45 |
Correct |
14 ms |
16120 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
15992 KB |
Output is correct |
2 |
Correct |
13 ms |
15992 KB |
Output is correct |
3 |
Correct |
13 ms |
15992 KB |
Output is correct |
4 |
Correct |
13 ms |
15992 KB |
Output is correct |
5 |
Correct |
13 ms |
15992 KB |
Output is correct |
6 |
Correct |
13 ms |
15992 KB |
Output is correct |
7 |
Correct |
13 ms |
15992 KB |
Output is correct |
8 |
Correct |
13 ms |
15996 KB |
Output is correct |
9 |
Correct |
13 ms |
15992 KB |
Output is correct |
10 |
Correct |
13 ms |
15992 KB |
Output is correct |
11 |
Correct |
13 ms |
15992 KB |
Output is correct |
12 |
Correct |
13 ms |
15992 KB |
Output is correct |
13 |
Correct |
13 ms |
15992 KB |
Output is correct |
14 |
Correct |
13 ms |
15992 KB |
Output is correct |
15 |
Correct |
13 ms |
15992 KB |
Output is correct |
16 |
Correct |
13 ms |
15992 KB |
Output is correct |
17 |
Correct |
14 ms |
15992 KB |
Output is correct |
18 |
Correct |
13 ms |
15992 KB |
Output is correct |
19 |
Correct |
13 ms |
15992 KB |
Output is correct |
20 |
Correct |
13 ms |
15992 KB |
Output is correct |
21 |
Correct |
13 ms |
15992 KB |
Output is correct |
22 |
Correct |
13 ms |
15992 KB |
Output is correct |
23 |
Correct |
13 ms |
15992 KB |
Output is correct |
24 |
Correct |
14 ms |
15992 KB |
Output is correct |
25 |
Correct |
13 ms |
15996 KB |
Output is correct |
26 |
Correct |
14 ms |
15992 KB |
Output is correct |
27 |
Correct |
13 ms |
15996 KB |
Output is correct |
28 |
Correct |
13 ms |
15992 KB |
Output is correct |
29 |
Correct |
13 ms |
15992 KB |
Output is correct |
30 |
Correct |
13 ms |
15992 KB |
Output is correct |
31 |
Correct |
14 ms |
16120 KB |
Output is correct |
32 |
Correct |
15 ms |
16120 KB |
Output is correct |
33 |
Correct |
15 ms |
16120 KB |
Output is correct |
34 |
Correct |
15 ms |
16120 KB |
Output is correct |
35 |
Correct |
14 ms |
16120 KB |
Output is correct |
36 |
Correct |
15 ms |
16120 KB |
Output is correct |
37 |
Correct |
14 ms |
16120 KB |
Output is correct |
38 |
Correct |
15 ms |
15992 KB |
Output is correct |
39 |
Correct |
14 ms |
16120 KB |
Output is correct |
40 |
Correct |
15 ms |
16124 KB |
Output is correct |
41 |
Correct |
14 ms |
15992 KB |
Output is correct |
42 |
Correct |
14 ms |
16120 KB |
Output is correct |
43 |
Correct |
14 ms |
16120 KB |
Output is correct |
44 |
Correct |
14 ms |
16120 KB |
Output is correct |
45 |
Correct |
14 ms |
16120 KB |
Output is correct |
46 |
Correct |
49 ms |
18680 KB |
Output is correct |
47 |
Correct |
56 ms |
18808 KB |
Output is correct |
48 |
Correct |
69 ms |
19192 KB |
Output is correct |
49 |
Correct |
72 ms |
19320 KB |
Output is correct |
50 |
Correct |
74 ms |
19320 KB |
Output is correct |
51 |
Correct |
77 ms |
19320 KB |
Output is correct |
52 |
Correct |
46 ms |
17656 KB |
Output is correct |
53 |
Correct |
33 ms |
17144 KB |
Output is correct |
54 |
Correct |
39 ms |
18552 KB |
Output is correct |
55 |
Correct |
76 ms |
19296 KB |
Output is correct |
56 |
Correct |
50 ms |
18808 KB |
Output is correct |
57 |
Correct |
49 ms |
18696 KB |
Output is correct |
58 |
Correct |
53 ms |
18808 KB |
Output is correct |
59 |
Correct |
57 ms |
19064 KB |
Output is correct |
60 |
Correct |
56 ms |
18936 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
15992 KB |
Output is correct |
2 |
Correct |
13 ms |
15992 KB |
Output is correct |
3 |
Correct |
13 ms |
15992 KB |
Output is correct |
4 |
Correct |
13 ms |
15992 KB |
Output is correct |
5 |
Correct |
13 ms |
15992 KB |
Output is correct |
6 |
Correct |
13 ms |
15992 KB |
Output is correct |
7 |
Correct |
13 ms |
15992 KB |
Output is correct |
8 |
Correct |
13 ms |
15996 KB |
Output is correct |
9 |
Correct |
13 ms |
15992 KB |
Output is correct |
10 |
Correct |
13 ms |
15992 KB |
Output is correct |
11 |
Correct |
13 ms |
15992 KB |
Output is correct |
12 |
Correct |
13 ms |
15992 KB |
Output is correct |
13 |
Correct |
13 ms |
15992 KB |
Output is correct |
14 |
Correct |
13 ms |
15992 KB |
Output is correct |
15 |
Correct |
13 ms |
15992 KB |
Output is correct |
16 |
Correct |
13 ms |
15992 KB |
Output is correct |
17 |
Correct |
14 ms |
15992 KB |
Output is correct |
18 |
Correct |
13 ms |
15992 KB |
Output is correct |
19 |
Correct |
13 ms |
15992 KB |
Output is correct |
20 |
Correct |
13 ms |
15992 KB |
Output is correct |
21 |
Correct |
13 ms |
15992 KB |
Output is correct |
22 |
Correct |
13 ms |
15992 KB |
Output is correct |
23 |
Correct |
13 ms |
15992 KB |
Output is correct |
24 |
Correct |
14 ms |
15992 KB |
Output is correct |
25 |
Correct |
13 ms |
15996 KB |
Output is correct |
26 |
Correct |
14 ms |
15992 KB |
Output is correct |
27 |
Correct |
13 ms |
15996 KB |
Output is correct |
28 |
Correct |
13 ms |
15992 KB |
Output is correct |
29 |
Correct |
13 ms |
15992 KB |
Output is correct |
30 |
Correct |
13 ms |
15992 KB |
Output is correct |
31 |
Correct |
14 ms |
16120 KB |
Output is correct |
32 |
Correct |
15 ms |
16120 KB |
Output is correct |
33 |
Correct |
15 ms |
16120 KB |
Output is correct |
34 |
Correct |
15 ms |
16120 KB |
Output is correct |
35 |
Correct |
14 ms |
16120 KB |
Output is correct |
36 |
Correct |
15 ms |
16120 KB |
Output is correct |
37 |
Correct |
14 ms |
16120 KB |
Output is correct |
38 |
Correct |
15 ms |
15992 KB |
Output is correct |
39 |
Correct |
14 ms |
16120 KB |
Output is correct |
40 |
Correct |
15 ms |
16124 KB |
Output is correct |
41 |
Correct |
14 ms |
15992 KB |
Output is correct |
42 |
Correct |
14 ms |
16120 KB |
Output is correct |
43 |
Correct |
14 ms |
16120 KB |
Output is correct |
44 |
Correct |
14 ms |
16120 KB |
Output is correct |
45 |
Correct |
14 ms |
16120 KB |
Output is correct |
46 |
Correct |
49 ms |
18680 KB |
Output is correct |
47 |
Correct |
56 ms |
18808 KB |
Output is correct |
48 |
Correct |
69 ms |
19192 KB |
Output is correct |
49 |
Correct |
72 ms |
19320 KB |
Output is correct |
50 |
Correct |
74 ms |
19320 KB |
Output is correct |
51 |
Correct |
77 ms |
19320 KB |
Output is correct |
52 |
Correct |
46 ms |
17656 KB |
Output is correct |
53 |
Correct |
33 ms |
17144 KB |
Output is correct |
54 |
Correct |
39 ms |
18552 KB |
Output is correct |
55 |
Correct |
76 ms |
19296 KB |
Output is correct |
56 |
Correct |
50 ms |
18808 KB |
Output is correct |
57 |
Correct |
49 ms |
18696 KB |
Output is correct |
58 |
Correct |
53 ms |
18808 KB |
Output is correct |
59 |
Correct |
57 ms |
19064 KB |
Output is correct |
60 |
Correct |
56 ms |
18936 KB |
Output is correct |
61 |
Correct |
192 ms |
29688 KB |
Output is correct |
62 |
Correct |
199 ms |
29696 KB |
Output is correct |
63 |
Correct |
217 ms |
30072 KB |
Output is correct |
64 |
Correct |
320 ms |
32360 KB |
Output is correct |
65 |
Correct |
332 ms |
32632 KB |
Output is correct |
66 |
Correct |
331 ms |
32504 KB |
Output is correct |
67 |
Correct |
267 ms |
29304 KB |
Output is correct |
68 |
Correct |
139 ms |
22648 KB |
Output is correct |
69 |
Correct |
140 ms |
28792 KB |
Output is correct |
70 |
Correct |
335 ms |
32632 KB |
Output is correct |
71 |
Correct |
179 ms |
29688 KB |
Output is correct |
72 |
Correct |
209 ms |
30048 KB |
Output is correct |
73 |
Correct |
232 ms |
30712 KB |
Output is correct |
74 |
Correct |
254 ms |
31096 KB |
Output is correct |
75 |
Correct |
250 ms |
31096 KB |
Output is correct |