#include <bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int N; cin >> N;
vector<int> v(N+1);
for (int i = 1; i <= N; i++) cin >> v[i]; v[0] = 0x3f3f3f3f;
vector<vector<int>> dp(N+1, vector<int>(N+1));
for (int l = 2; l <= N; l++)
{
vector<int> prefdp(N+1);
for (int k = 1; k < l; k++) prefdp[k] = max(prefdp[k-1], dp[k][l-1]);
// cerr << "l: " << l << '\n';
int sumL = v[l-1], sumR = 0, p = l-1, inters = 0, mSuf = 0;
for (int r = l; r <= N; r++)
{
dp[l][r] = max(prefdp[p] + inters, mSuf);
sumR += v[r];
while (p > 1 && sumL <= sumR)
{
mSuf = max(mSuf, dp[p][l-1] + inters);
if (sumL == sumR) inters++;
sumL += v[--p];
}
// cerr << dp[l][r] << " ";
}
// cerr << '\n';
}
int resp = 0;
for (int i = 1; i <= N; i++) resp = max(resp, dp[i][N]);
cout << resp << '\n';
}
Compilation message
cigle.cpp: In function 'int main()':
cigle.cpp:10:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
10 | for (int i = 1; i <= N; i++) cin >> v[i]; v[0] = 0x3f3f3f3f;
| ^~~
cigle.cpp:10:47: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
10 | for (int i = 1; i <= N; i++) cin >> v[i]; v[0] = 0x3f3f3f3f;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 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 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 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 |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1372 KB |
Output is correct |
2 |
Correct |
1 ms |
1372 KB |
Output is correct |
3 |
Correct |
1 ms |
1372 KB |
Output is correct |
4 |
Correct |
1 ms |
1372 KB |
Output is correct |
5 |
Correct |
1 ms |
1372 KB |
Output is correct |
6 |
Correct |
1 ms |
1372 KB |
Output is correct |
7 |
Correct |
1 ms |
1372 KB |
Output is correct |
8 |
Correct |
1 ms |
1368 KB |
Output is correct |
9 |
Correct |
1 ms |
1372 KB |
Output is correct |
10 |
Correct |
1 ms |
1372 KB |
Output is correct |
11 |
Correct |
1 ms |
1372 KB |
Output is correct |
12 |
Correct |
1 ms |
1372 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 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 |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
1372 KB |
Output is correct |
22 |
Correct |
1 ms |
1372 KB |
Output is correct |
23 |
Correct |
1 ms |
1372 KB |
Output is correct |
24 |
Correct |
1 ms |
1372 KB |
Output is correct |
25 |
Correct |
1 ms |
1372 KB |
Output is correct |
26 |
Correct |
1 ms |
1372 KB |
Output is correct |
27 |
Correct |
1 ms |
1372 KB |
Output is correct |
28 |
Correct |
1 ms |
1368 KB |
Output is correct |
29 |
Correct |
1 ms |
1372 KB |
Output is correct |
30 |
Correct |
1 ms |
1372 KB |
Output is correct |
31 |
Correct |
1 ms |
1372 KB |
Output is correct |
32 |
Correct |
1 ms |
1372 KB |
Output is correct |
33 |
Correct |
1 ms |
1372 KB |
Output is correct |
34 |
Correct |
1 ms |
1372 KB |
Output is correct |
35 |
Correct |
1 ms |
1368 KB |
Output is correct |
36 |
Correct |
1 ms |
1372 KB |
Output is correct |
37 |
Correct |
1 ms |
1448 KB |
Output is correct |
38 |
Correct |
1 ms |
1372 KB |
Output is correct |
39 |
Correct |
1 ms |
1372 KB |
Output is correct |
40 |
Correct |
1 ms |
1372 KB |
Output is correct |
41 |
Correct |
2 ms |
1372 KB |
Output is correct |
42 |
Correct |
1 ms |
1372 KB |
Output is correct |
43 |
Correct |
1 ms |
1372 KB |
Output is correct |
44 |
Correct |
1 ms |
1372 KB |
Output is correct |
45 |
Correct |
1 ms |
1372 KB |
Output is correct |
46 |
Correct |
1 ms |
1372 KB |
Output is correct |
47 |
Correct |
1 ms |
1460 KB |
Output is correct |
48 |
Correct |
1 ms |
1468 KB |
Output is correct |
49 |
Correct |
1 ms |
1372 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 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 |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
1372 KB |
Output is correct |
22 |
Correct |
1 ms |
1372 KB |
Output is correct |
23 |
Correct |
1 ms |
1372 KB |
Output is correct |
24 |
Correct |
1 ms |
1372 KB |
Output is correct |
25 |
Correct |
1 ms |
1372 KB |
Output is correct |
26 |
Correct |
1 ms |
1372 KB |
Output is correct |
27 |
Correct |
1 ms |
1372 KB |
Output is correct |
28 |
Correct |
1 ms |
1368 KB |
Output is correct |
29 |
Correct |
1 ms |
1372 KB |
Output is correct |
30 |
Correct |
1 ms |
1372 KB |
Output is correct |
31 |
Correct |
1 ms |
1372 KB |
Output is correct |
32 |
Correct |
1 ms |
1372 KB |
Output is correct |
33 |
Correct |
1 ms |
1372 KB |
Output is correct |
34 |
Correct |
1 ms |
1372 KB |
Output is correct |
35 |
Correct |
1 ms |
1368 KB |
Output is correct |
36 |
Correct |
1 ms |
1372 KB |
Output is correct |
37 |
Correct |
1 ms |
1448 KB |
Output is correct |
38 |
Correct |
1 ms |
1372 KB |
Output is correct |
39 |
Correct |
1 ms |
1372 KB |
Output is correct |
40 |
Correct |
1 ms |
1372 KB |
Output is correct |
41 |
Correct |
2 ms |
1372 KB |
Output is correct |
42 |
Correct |
1 ms |
1372 KB |
Output is correct |
43 |
Correct |
1 ms |
1372 KB |
Output is correct |
44 |
Correct |
1 ms |
1372 KB |
Output is correct |
45 |
Correct |
1 ms |
1372 KB |
Output is correct |
46 |
Correct |
1 ms |
1372 KB |
Output is correct |
47 |
Correct |
1 ms |
1460 KB |
Output is correct |
48 |
Correct |
1 ms |
1468 KB |
Output is correct |
49 |
Correct |
1 ms |
1372 KB |
Output is correct |
50 |
Correct |
108 ms |
98396 KB |
Output is correct |
51 |
Correct |
107 ms |
98388 KB |
Output is correct |
52 |
Correct |
115 ms |
98384 KB |
Output is correct |
53 |
Correct |
112 ms |
98496 KB |
Output is correct |
54 |
Correct |
112 ms |
98552 KB |
Output is correct |
55 |
Correct |
105 ms |
98384 KB |
Output is correct |
56 |
Correct |
133 ms |
98384 KB |
Output is correct |
57 |
Correct |
121 ms |
98348 KB |
Output is correct |
58 |
Correct |
137 ms |
98548 KB |
Output is correct |
59 |
Correct |
133 ms |
98396 KB |
Output is correct |
60 |
Correct |
137 ms |
98384 KB |
Output is correct |
61 |
Correct |
125 ms |
98560 KB |
Output is correct |
62 |
Correct |
121 ms |
98384 KB |
Output is correct |
63 |
Correct |
119 ms |
98556 KB |
Output is correct |
64 |
Correct |
118 ms |
98556 KB |
Output is correct |
65 |
Correct |
116 ms |
98388 KB |
Output is correct |
66 |
Correct |
122 ms |
98388 KB |
Output is correct |
67 |
Correct |
120 ms |
98552 KB |
Output is correct |
68 |
Correct |
123 ms |
98388 KB |
Output is correct |
69 |
Correct |
112 ms |
98388 KB |
Output is correct |
70 |
Correct |
133 ms |
98388 KB |
Output is correct |
71 |
Correct |
145 ms |
98552 KB |
Output is correct |
72 |
Correct |
129 ms |
98420 KB |
Output is correct |