// Nurstan Duisengaliev
// не, не надо меня узнавать
/*#pragma GCC target ("avx2")
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("O3")*/
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define all(x) x.begin(), x.end()
#define in insert
#define mp make_pair
#define F first
#define S second
#define ppf pop_front
#define pb push_back
#define ppb pop_back
#define pf push_front
#define pii pair <int, int>
#define pll pair <ll, ll>
#define boost() ios_base::sync_with_stdio(0), cin.tie(0)
#define sz(x) (int)x.size()
using namespace std;
//using namespace __gnu_pbds;
//template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const int N = 3005;
const int mod = (int)1e9 + 7;
const ll INF = (ll)1e18 + 1;
int n;
ll a[N], pref[N];
int dp[N][N];
void solve () {
cin >> n;
for (int i = 1; i <= n; i ++) {
cin >> a[i];
pref[i] = pref[i - 1] + a[i];
for (int j = 1; j <= n; j ++) dp[i][j] = -1;
dp[i][i] = 1;
}
for (int i = 1; i < n; i ++) {
for (int j = 1; j <= i; j ++) {
ll x = pref[i] - pref[i - j];
if (dp[i][j] != -1) {
dp[i + 1][j + 1] = max (dp[i + 1][j + 1], dp[i][j]);
int pos = -1;
int l = i + 1, r = n;
while (l <= r) {
int mid = l + r >> 1;
if (pref[mid] - pref[i] >= x) {
r = mid - 1;
pos = mid;
}
else {
l = mid + 1;
}
}
if (pos != -1) dp[pos][pos - i] = max (dp[pos][pos - i], dp[i][j] + 1);
}
}
}
int maxi = 0;
for (int i = 1; i <= n; i ++) {
maxi = max (maxi, dp[n][i]);
}
cout << maxi;
}
main () {
// freopen (".in", "r", stdin);
// freopen (".out", "w", stdout);
boost ();
int TT = 1;
// cin >> TT;
while (TT --) {
solve ();
}
return 0;
}
Compilation message
segments.cpp: In function 'void solve()':
segments.cpp:55:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
55 | int mid = l + r >> 1;
| ~~^~~
segments.cpp: At global scope:
segments.cpp:75:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
75 | main () {
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
0 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
512 KB |
Output is correct |
13 |
Correct |
1 ms |
504 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
0 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
512 KB |
Output is correct |
13 |
Correct |
1 ms |
504 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
3 ms |
3308 KB |
Output is correct |
17 |
Correct |
4 ms |
3308 KB |
Output is correct |
18 |
Correct |
4 ms |
3308 KB |
Output is correct |
19 |
Correct |
3 ms |
3308 KB |
Output is correct |
20 |
Correct |
4 ms |
3308 KB |
Output is correct |
21 |
Correct |
5 ms |
3308 KB |
Output is correct |
22 |
Correct |
3 ms |
2668 KB |
Output is correct |
23 |
Correct |
2 ms |
1900 KB |
Output is correct |
24 |
Correct |
5 ms |
3308 KB |
Output is correct |
25 |
Correct |
4 ms |
3308 KB |
Output is correct |
26 |
Correct |
4 ms |
3308 KB |
Output is correct |
27 |
Correct |
3 ms |
3308 KB |
Output is correct |
28 |
Correct |
4 ms |
3308 KB |
Output is correct |
29 |
Correct |
5 ms |
3308 KB |
Output is correct |
30 |
Correct |
4 ms |
3308 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
0 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
512 KB |
Output is correct |
13 |
Correct |
1 ms |
504 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
3 ms |
3308 KB |
Output is correct |
17 |
Correct |
4 ms |
3308 KB |
Output is correct |
18 |
Correct |
4 ms |
3308 KB |
Output is correct |
19 |
Correct |
3 ms |
3308 KB |
Output is correct |
20 |
Correct |
4 ms |
3308 KB |
Output is correct |
21 |
Correct |
5 ms |
3308 KB |
Output is correct |
22 |
Correct |
3 ms |
2668 KB |
Output is correct |
23 |
Correct |
2 ms |
1900 KB |
Output is correct |
24 |
Correct |
5 ms |
3308 KB |
Output is correct |
25 |
Correct |
4 ms |
3308 KB |
Output is correct |
26 |
Correct |
4 ms |
3308 KB |
Output is correct |
27 |
Correct |
3 ms |
3308 KB |
Output is correct |
28 |
Correct |
4 ms |
3308 KB |
Output is correct |
29 |
Correct |
5 ms |
3308 KB |
Output is correct |
30 |
Correct |
4 ms |
3308 KB |
Output is correct |
31 |
Correct |
27 ms |
35692 KB |
Output is correct |
32 |
Correct |
80 ms |
35692 KB |
Output is correct |
33 |
Correct |
125 ms |
35712 KB |
Output is correct |
34 |
Correct |
80 ms |
35692 KB |
Output is correct |
35 |
Correct |
127 ms |
35692 KB |
Output is correct |
36 |
Correct |
149 ms |
35820 KB |
Output is correct |
37 |
Correct |
103 ms |
29932 KB |
Output is correct |
38 |
Correct |
63 ms |
23936 KB |
Output is correct |
39 |
Correct |
145 ms |
35692 KB |
Output is correct |
40 |
Correct |
127 ms |
35692 KB |
Output is correct |
41 |
Correct |
121 ms |
35692 KB |
Output is correct |
42 |
Correct |
91 ms |
35820 KB |
Output is correct |
43 |
Correct |
96 ms |
35820 KB |
Output is correct |
44 |
Correct |
121 ms |
35740 KB |
Output is correct |
45 |
Correct |
117 ms |
35692 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
0 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
512 KB |
Output is correct |
13 |
Correct |
1 ms |
504 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
3 ms |
3308 KB |
Output is correct |
17 |
Correct |
4 ms |
3308 KB |
Output is correct |
18 |
Correct |
4 ms |
3308 KB |
Output is correct |
19 |
Correct |
3 ms |
3308 KB |
Output is correct |
20 |
Correct |
4 ms |
3308 KB |
Output is correct |
21 |
Correct |
5 ms |
3308 KB |
Output is correct |
22 |
Correct |
3 ms |
2668 KB |
Output is correct |
23 |
Correct |
2 ms |
1900 KB |
Output is correct |
24 |
Correct |
5 ms |
3308 KB |
Output is correct |
25 |
Correct |
4 ms |
3308 KB |
Output is correct |
26 |
Correct |
4 ms |
3308 KB |
Output is correct |
27 |
Correct |
3 ms |
3308 KB |
Output is correct |
28 |
Correct |
4 ms |
3308 KB |
Output is correct |
29 |
Correct |
5 ms |
3308 KB |
Output is correct |
30 |
Correct |
4 ms |
3308 KB |
Output is correct |
31 |
Correct |
27 ms |
35692 KB |
Output is correct |
32 |
Correct |
80 ms |
35692 KB |
Output is correct |
33 |
Correct |
125 ms |
35712 KB |
Output is correct |
34 |
Correct |
80 ms |
35692 KB |
Output is correct |
35 |
Correct |
127 ms |
35692 KB |
Output is correct |
36 |
Correct |
149 ms |
35820 KB |
Output is correct |
37 |
Correct |
103 ms |
29932 KB |
Output is correct |
38 |
Correct |
63 ms |
23936 KB |
Output is correct |
39 |
Correct |
145 ms |
35692 KB |
Output is correct |
40 |
Correct |
127 ms |
35692 KB |
Output is correct |
41 |
Correct |
121 ms |
35692 KB |
Output is correct |
42 |
Correct |
91 ms |
35820 KB |
Output is correct |
43 |
Correct |
96 ms |
35820 KB |
Output is correct |
44 |
Correct |
121 ms |
35740 KB |
Output is correct |
45 |
Correct |
117 ms |
35692 KB |
Output is correct |
46 |
Runtime error |
223 ms |
72172 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
47 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
0 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
512 KB |
Output is correct |
13 |
Correct |
1 ms |
504 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
3 ms |
3308 KB |
Output is correct |
17 |
Correct |
4 ms |
3308 KB |
Output is correct |
18 |
Correct |
4 ms |
3308 KB |
Output is correct |
19 |
Correct |
3 ms |
3308 KB |
Output is correct |
20 |
Correct |
4 ms |
3308 KB |
Output is correct |
21 |
Correct |
5 ms |
3308 KB |
Output is correct |
22 |
Correct |
3 ms |
2668 KB |
Output is correct |
23 |
Correct |
2 ms |
1900 KB |
Output is correct |
24 |
Correct |
5 ms |
3308 KB |
Output is correct |
25 |
Correct |
4 ms |
3308 KB |
Output is correct |
26 |
Correct |
4 ms |
3308 KB |
Output is correct |
27 |
Correct |
3 ms |
3308 KB |
Output is correct |
28 |
Correct |
4 ms |
3308 KB |
Output is correct |
29 |
Correct |
5 ms |
3308 KB |
Output is correct |
30 |
Correct |
4 ms |
3308 KB |
Output is correct |
31 |
Correct |
27 ms |
35692 KB |
Output is correct |
32 |
Correct |
80 ms |
35692 KB |
Output is correct |
33 |
Correct |
125 ms |
35712 KB |
Output is correct |
34 |
Correct |
80 ms |
35692 KB |
Output is correct |
35 |
Correct |
127 ms |
35692 KB |
Output is correct |
36 |
Correct |
149 ms |
35820 KB |
Output is correct |
37 |
Correct |
103 ms |
29932 KB |
Output is correct |
38 |
Correct |
63 ms |
23936 KB |
Output is correct |
39 |
Correct |
145 ms |
35692 KB |
Output is correct |
40 |
Correct |
127 ms |
35692 KB |
Output is correct |
41 |
Correct |
121 ms |
35692 KB |
Output is correct |
42 |
Correct |
91 ms |
35820 KB |
Output is correct |
43 |
Correct |
96 ms |
35820 KB |
Output is correct |
44 |
Correct |
121 ms |
35740 KB |
Output is correct |
45 |
Correct |
117 ms |
35692 KB |
Output is correct |
46 |
Runtime error |
223 ms |
72172 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
47 |
Halted |
0 ms |
0 KB |
- |