#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ar array
const int mxN=5000;
int n, a[mxN], dp[mxN][mxN], need[mxN];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for (int i=0; i<n; ++i)
cin >> a[i];
for (int i=0; i<n; ++i) {
//for (int j=0; j<=i; ++j)
// cout << i << " " << j << " " << dp[i][j] << "\n";
for (int j=i-1; ~j; --j)
dp[i][j]=max(dp[i][j], dp[i][j+1]);
vector<ar<int, 2>> oc;
int ind=i, left=a[i];
for (int j=i+1; j<n; ++j) {
left-=a[j];
while(ind>0&&left<0)
left+=a[--ind];
if (ind>0&&left==0) {
left+=a[--ind];
oc.push_back({j+1, i-ind});
}
}
int cur=dp[i][0];
for (int j=i+1, k=0; j<n; ++j) {
if (k<oc.size()&&oc[k][0]==j) {
cur=max(cur, dp[i][oc[k][1]]+k+1);
++k;
}
dp[j][j-i-1]=max(dp[j][j-i-1], cur);
}
}
cout << *max_element(dp[n-1], dp[n-1]+n);
return 0;
}
Compilation message
cigle.cpp: In function 'int main()':
cigle.cpp:34:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
34 | if (k<oc.size()&&oc[k][0]==j) {
| ~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
328 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
324 KB |
Output is correct |
8 |
Correct |
1 ms |
460 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
328 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
324 KB |
Output is correct |
8 |
Correct |
1 ms |
460 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
596 KB |
Output is correct |
11 |
Correct |
1 ms |
596 KB |
Output is correct |
12 |
Correct |
1 ms |
596 KB |
Output is correct |
13 |
Correct |
1 ms |
580 KB |
Output is correct |
14 |
Correct |
1 ms |
596 KB |
Output is correct |
15 |
Correct |
1 ms |
596 KB |
Output is correct |
16 |
Correct |
1 ms |
596 KB |
Output is correct |
17 |
Correct |
1 ms |
596 KB |
Output is correct |
18 |
Correct |
1 ms |
596 KB |
Output is correct |
19 |
Correct |
1 ms |
596 KB |
Output is correct |
20 |
Correct |
1 ms |
596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
2772 KB |
Output is correct |
2 |
Correct |
3 ms |
2772 KB |
Output is correct |
3 |
Correct |
3 ms |
2772 KB |
Output is correct |
4 |
Correct |
3 ms |
2772 KB |
Output is correct |
5 |
Correct |
4 ms |
2772 KB |
Output is correct |
6 |
Correct |
3 ms |
2772 KB |
Output is correct |
7 |
Correct |
4 ms |
2772 KB |
Output is correct |
8 |
Correct |
4 ms |
2760 KB |
Output is correct |
9 |
Correct |
3 ms |
2772 KB |
Output is correct |
10 |
Correct |
3 ms |
2772 KB |
Output is correct |
11 |
Correct |
4 ms |
2764 KB |
Output is correct |
12 |
Correct |
4 ms |
2772 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
328 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
324 KB |
Output is correct |
8 |
Correct |
1 ms |
460 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
596 KB |
Output is correct |
11 |
Correct |
1 ms |
596 KB |
Output is correct |
12 |
Correct |
1 ms |
596 KB |
Output is correct |
13 |
Correct |
1 ms |
580 KB |
Output is correct |
14 |
Correct |
1 ms |
596 KB |
Output is correct |
15 |
Correct |
1 ms |
596 KB |
Output is correct |
16 |
Correct |
1 ms |
596 KB |
Output is correct |
17 |
Correct |
1 ms |
596 KB |
Output is correct |
18 |
Correct |
1 ms |
596 KB |
Output is correct |
19 |
Correct |
1 ms |
596 KB |
Output is correct |
20 |
Correct |
1 ms |
596 KB |
Output is correct |
21 |
Correct |
3 ms |
2772 KB |
Output is correct |
22 |
Correct |
3 ms |
2772 KB |
Output is correct |
23 |
Correct |
3 ms |
2772 KB |
Output is correct |
24 |
Correct |
3 ms |
2772 KB |
Output is correct |
25 |
Correct |
4 ms |
2772 KB |
Output is correct |
26 |
Correct |
3 ms |
2772 KB |
Output is correct |
27 |
Correct |
4 ms |
2772 KB |
Output is correct |
28 |
Correct |
4 ms |
2760 KB |
Output is correct |
29 |
Correct |
3 ms |
2772 KB |
Output is correct |
30 |
Correct |
3 ms |
2772 KB |
Output is correct |
31 |
Correct |
4 ms |
2764 KB |
Output is correct |
32 |
Correct |
4 ms |
2772 KB |
Output is correct |
33 |
Correct |
4 ms |
2772 KB |
Output is correct |
34 |
Correct |
3 ms |
2772 KB |
Output is correct |
35 |
Correct |
3 ms |
2772 KB |
Output is correct |
36 |
Correct |
3 ms |
2772 KB |
Output is correct |
37 |
Correct |
4 ms |
2900 KB |
Output is correct |
38 |
Correct |
4 ms |
2704 KB |
Output is correct |
39 |
Correct |
4 ms |
2772 KB |
Output is correct |
40 |
Correct |
3 ms |
2772 KB |
Output is correct |
41 |
Correct |
4 ms |
2772 KB |
Output is correct |
42 |
Correct |
4 ms |
2772 KB |
Output is correct |
43 |
Correct |
3 ms |
2772 KB |
Output is correct |
44 |
Correct |
4 ms |
2772 KB |
Output is correct |
45 |
Correct |
3 ms |
2760 KB |
Output is correct |
46 |
Correct |
3 ms |
2772 KB |
Output is correct |
47 |
Correct |
4 ms |
2756 KB |
Output is correct |
48 |
Correct |
3 ms |
2772 KB |
Output is correct |
49 |
Correct |
4 ms |
2756 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
328 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
324 KB |
Output is correct |
8 |
Correct |
1 ms |
460 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
596 KB |
Output is correct |
11 |
Correct |
1 ms |
596 KB |
Output is correct |
12 |
Correct |
1 ms |
596 KB |
Output is correct |
13 |
Correct |
1 ms |
580 KB |
Output is correct |
14 |
Correct |
1 ms |
596 KB |
Output is correct |
15 |
Correct |
1 ms |
596 KB |
Output is correct |
16 |
Correct |
1 ms |
596 KB |
Output is correct |
17 |
Correct |
1 ms |
596 KB |
Output is correct |
18 |
Correct |
1 ms |
596 KB |
Output is correct |
19 |
Correct |
1 ms |
596 KB |
Output is correct |
20 |
Correct |
1 ms |
596 KB |
Output is correct |
21 |
Correct |
3 ms |
2772 KB |
Output is correct |
22 |
Correct |
3 ms |
2772 KB |
Output is correct |
23 |
Correct |
3 ms |
2772 KB |
Output is correct |
24 |
Correct |
3 ms |
2772 KB |
Output is correct |
25 |
Correct |
4 ms |
2772 KB |
Output is correct |
26 |
Correct |
3 ms |
2772 KB |
Output is correct |
27 |
Correct |
4 ms |
2772 KB |
Output is correct |
28 |
Correct |
4 ms |
2760 KB |
Output is correct |
29 |
Correct |
3 ms |
2772 KB |
Output is correct |
30 |
Correct |
3 ms |
2772 KB |
Output is correct |
31 |
Correct |
4 ms |
2764 KB |
Output is correct |
32 |
Correct |
4 ms |
2772 KB |
Output is correct |
33 |
Correct |
4 ms |
2772 KB |
Output is correct |
34 |
Correct |
3 ms |
2772 KB |
Output is correct |
35 |
Correct |
3 ms |
2772 KB |
Output is correct |
36 |
Correct |
3 ms |
2772 KB |
Output is correct |
37 |
Correct |
4 ms |
2900 KB |
Output is correct |
38 |
Correct |
4 ms |
2704 KB |
Output is correct |
39 |
Correct |
4 ms |
2772 KB |
Output is correct |
40 |
Correct |
3 ms |
2772 KB |
Output is correct |
41 |
Correct |
4 ms |
2772 KB |
Output is correct |
42 |
Correct |
4 ms |
2772 KB |
Output is correct |
43 |
Correct |
3 ms |
2772 KB |
Output is correct |
44 |
Correct |
4 ms |
2772 KB |
Output is correct |
45 |
Correct |
3 ms |
2760 KB |
Output is correct |
46 |
Correct |
3 ms |
2772 KB |
Output is correct |
47 |
Correct |
4 ms |
2756 KB |
Output is correct |
48 |
Correct |
3 ms |
2772 KB |
Output is correct |
49 |
Correct |
4 ms |
2756 KB |
Output is correct |
50 |
Correct |
297 ms |
67176 KB |
Output is correct |
51 |
Correct |
273 ms |
67152 KB |
Output is correct |
52 |
Correct |
276 ms |
67252 KB |
Output is correct |
53 |
Correct |
283 ms |
67260 KB |
Output is correct |
54 |
Correct |
295 ms |
67228 KB |
Output is correct |
55 |
Correct |
272 ms |
67232 KB |
Output is correct |
56 |
Correct |
306 ms |
67268 KB |
Output is correct |
57 |
Correct |
326 ms |
67152 KB |
Output is correct |
58 |
Correct |
323 ms |
67148 KB |
Output is correct |
59 |
Correct |
261 ms |
67196 KB |
Output is correct |
60 |
Correct |
278 ms |
67232 KB |
Output is correct |
61 |
Correct |
253 ms |
67268 KB |
Output is correct |
62 |
Correct |
230 ms |
67124 KB |
Output is correct |
63 |
Correct |
235 ms |
67180 KB |
Output is correct |
64 |
Correct |
240 ms |
67164 KB |
Output is correct |
65 |
Correct |
252 ms |
67156 KB |
Output is correct |
66 |
Correct |
239 ms |
67172 KB |
Output is correct |
67 |
Correct |
220 ms |
67220 KB |
Output is correct |
68 |
Correct |
225 ms |
67188 KB |
Output is correct |
69 |
Correct |
231 ms |
67148 KB |
Output is correct |
70 |
Correct |
269 ms |
67324 KB |
Output is correct |
71 |
Correct |
267 ms |
67244 KB |
Output is correct |
72 |
Correct |
246 ms |
67232 KB |
Output is correct |