#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int n;
vector<ll> a;
ll solve() {
vector<vector<int>> dp(n + 1, vector<int>(n + 1, 0));
for (int i = n; i >= 1; i--) {
for (int j = i; j <= n; j++) {
auto itr = lower_bound(a.begin(), a.end(), 2 * a[j] - a[i - 1]);
if (itr == a.end()) dp[i][j] = 1;
else dp[i][j] = 1 + dp[j + 1][itr - a.begin()];
}
for (int j = n - 1; j >= i; j--) {
dp[i][j] = max(dp[i][j], dp[i][j + 1]);
}
}
return dp[1][1];
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
a.resize(n + 1, 0);
for (int i = 1; i <= n; i++) {
cin >> a[i];
a[i] += a[i - 1];
}
cout << solve() << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
456 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
456 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
1368 KB |
Output is correct |
17 |
Correct |
3 ms |
1372 KB |
Output is correct |
18 |
Correct |
3 ms |
1372 KB |
Output is correct |
19 |
Correct |
2 ms |
1372 KB |
Output is correct |
20 |
Correct |
2 ms |
1368 KB |
Output is correct |
21 |
Correct |
4 ms |
1628 KB |
Output is correct |
22 |
Correct |
3 ms |
860 KB |
Output is correct |
23 |
Correct |
1 ms |
604 KB |
Output is correct |
24 |
Correct |
4 ms |
1220 KB |
Output is correct |
25 |
Correct |
3 ms |
1372 KB |
Output is correct |
26 |
Correct |
3 ms |
1368 KB |
Output is correct |
27 |
Correct |
2 ms |
1372 KB |
Output is correct |
28 |
Correct |
3 ms |
1228 KB |
Output is correct |
29 |
Correct |
3 ms |
1624 KB |
Output is correct |
30 |
Correct |
3 ms |
1228 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
456 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
1368 KB |
Output is correct |
17 |
Correct |
3 ms |
1372 KB |
Output is correct |
18 |
Correct |
3 ms |
1372 KB |
Output is correct |
19 |
Correct |
2 ms |
1372 KB |
Output is correct |
20 |
Correct |
2 ms |
1368 KB |
Output is correct |
21 |
Correct |
4 ms |
1628 KB |
Output is correct |
22 |
Correct |
3 ms |
860 KB |
Output is correct |
23 |
Correct |
1 ms |
604 KB |
Output is correct |
24 |
Correct |
4 ms |
1220 KB |
Output is correct |
25 |
Correct |
3 ms |
1372 KB |
Output is correct |
26 |
Correct |
3 ms |
1368 KB |
Output is correct |
27 |
Correct |
2 ms |
1372 KB |
Output is correct |
28 |
Correct |
3 ms |
1228 KB |
Output is correct |
29 |
Correct |
3 ms |
1624 KB |
Output is correct |
30 |
Correct |
3 ms |
1228 KB |
Output is correct |
31 |
Correct |
137 ms |
35672 KB |
Output is correct |
32 |
Correct |
92 ms |
35932 KB |
Output is correct |
33 |
Correct |
117 ms |
35676 KB |
Output is correct |
34 |
Correct |
97 ms |
35840 KB |
Output is correct |
35 |
Correct |
139 ms |
35852 KB |
Output is correct |
36 |
Correct |
153 ms |
35780 KB |
Output is correct |
37 |
Correct |
105 ms |
25056 KB |
Output is correct |
38 |
Correct |
64 ms |
16216 KB |
Output is correct |
39 |
Correct |
152 ms |
35828 KB |
Output is correct |
40 |
Correct |
140 ms |
35852 KB |
Output is correct |
41 |
Correct |
139 ms |
35676 KB |
Output is correct |
42 |
Correct |
114 ms |
35832 KB |
Output is correct |
43 |
Correct |
134 ms |
35828 KB |
Output is correct |
44 |
Correct |
169 ms |
35836 KB |
Output is correct |
45 |
Correct |
133 ms |
35836 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
456 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
1368 KB |
Output is correct |
17 |
Correct |
3 ms |
1372 KB |
Output is correct |
18 |
Correct |
3 ms |
1372 KB |
Output is correct |
19 |
Correct |
2 ms |
1372 KB |
Output is correct |
20 |
Correct |
2 ms |
1368 KB |
Output is correct |
21 |
Correct |
4 ms |
1628 KB |
Output is correct |
22 |
Correct |
3 ms |
860 KB |
Output is correct |
23 |
Correct |
1 ms |
604 KB |
Output is correct |
24 |
Correct |
4 ms |
1220 KB |
Output is correct |
25 |
Correct |
3 ms |
1372 KB |
Output is correct |
26 |
Correct |
3 ms |
1368 KB |
Output is correct |
27 |
Correct |
2 ms |
1372 KB |
Output is correct |
28 |
Correct |
3 ms |
1228 KB |
Output is correct |
29 |
Correct |
3 ms |
1624 KB |
Output is correct |
30 |
Correct |
3 ms |
1228 KB |
Output is correct |
31 |
Correct |
137 ms |
35672 KB |
Output is correct |
32 |
Correct |
92 ms |
35932 KB |
Output is correct |
33 |
Correct |
117 ms |
35676 KB |
Output is correct |
34 |
Correct |
97 ms |
35840 KB |
Output is correct |
35 |
Correct |
139 ms |
35852 KB |
Output is correct |
36 |
Correct |
153 ms |
35780 KB |
Output is correct |
37 |
Correct |
105 ms |
25056 KB |
Output is correct |
38 |
Correct |
64 ms |
16216 KB |
Output is correct |
39 |
Correct |
152 ms |
35828 KB |
Output is correct |
40 |
Correct |
140 ms |
35852 KB |
Output is correct |
41 |
Correct |
139 ms |
35676 KB |
Output is correct |
42 |
Correct |
114 ms |
35832 KB |
Output is correct |
43 |
Correct |
134 ms |
35828 KB |
Output is correct |
44 |
Correct |
169 ms |
35836 KB |
Output is correct |
45 |
Correct |
133 ms |
35836 KB |
Output is correct |
46 |
Runtime error |
125 ms |
262144 KB |
Execution killed with signal 9 |
47 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
456 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
1368 KB |
Output is correct |
17 |
Correct |
3 ms |
1372 KB |
Output is correct |
18 |
Correct |
3 ms |
1372 KB |
Output is correct |
19 |
Correct |
2 ms |
1372 KB |
Output is correct |
20 |
Correct |
2 ms |
1368 KB |
Output is correct |
21 |
Correct |
4 ms |
1628 KB |
Output is correct |
22 |
Correct |
3 ms |
860 KB |
Output is correct |
23 |
Correct |
1 ms |
604 KB |
Output is correct |
24 |
Correct |
4 ms |
1220 KB |
Output is correct |
25 |
Correct |
3 ms |
1372 KB |
Output is correct |
26 |
Correct |
3 ms |
1368 KB |
Output is correct |
27 |
Correct |
2 ms |
1372 KB |
Output is correct |
28 |
Correct |
3 ms |
1228 KB |
Output is correct |
29 |
Correct |
3 ms |
1624 KB |
Output is correct |
30 |
Correct |
3 ms |
1228 KB |
Output is correct |
31 |
Correct |
137 ms |
35672 KB |
Output is correct |
32 |
Correct |
92 ms |
35932 KB |
Output is correct |
33 |
Correct |
117 ms |
35676 KB |
Output is correct |
34 |
Correct |
97 ms |
35840 KB |
Output is correct |
35 |
Correct |
139 ms |
35852 KB |
Output is correct |
36 |
Correct |
153 ms |
35780 KB |
Output is correct |
37 |
Correct |
105 ms |
25056 KB |
Output is correct |
38 |
Correct |
64 ms |
16216 KB |
Output is correct |
39 |
Correct |
152 ms |
35828 KB |
Output is correct |
40 |
Correct |
140 ms |
35852 KB |
Output is correct |
41 |
Correct |
139 ms |
35676 KB |
Output is correct |
42 |
Correct |
114 ms |
35832 KB |
Output is correct |
43 |
Correct |
134 ms |
35828 KB |
Output is correct |
44 |
Correct |
169 ms |
35836 KB |
Output is correct |
45 |
Correct |
133 ms |
35836 KB |
Output is correct |
46 |
Runtime error |
125 ms |
262144 KB |
Execution killed with signal 9 |
47 |
Halted |
0 ms |
0 KB |
- |