#include <bits/stdc++.h>
using namespace std;
int n;
long long a[3001];
int dp[3001][3001];
int main(){
cin >> n;
for(int i = 1; i <= n; i++){
cin >> a[i];
dp[1][i] = 1;
}
for(int i = 2; i <= n; i++){
int po = i - 1;
long long sum = 0;
long long sum2 = 0;
int mx = 0;
for(int j = i; j <= n; j++){
sum += a[j];
while(po > 0 && sum2 + a[po] <= sum){
sum2 += a[po];
mx = max(dp[po][i - 1], mx);
po--;
}
if(po < i - 1 && mx > 0){
dp[i][j] = max(mx + 1, dp[i][j]);
}
}
}
int mx = 0;
for(int i = 1; i <= n; i++){
mx = max(dp[i][n], mx);
}
cout << mx;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
380 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
348 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
380 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
380 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
348 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
380 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
3 ms |
376 KB |
Output is correct |
17 |
Correct |
5 ms |
2552 KB |
Output is correct |
18 |
Correct |
7 ms |
2680 KB |
Output is correct |
19 |
Correct |
5 ms |
1912 KB |
Output is correct |
20 |
Correct |
12 ms |
2808 KB |
Output is correct |
21 |
Correct |
6 ms |
2680 KB |
Output is correct |
22 |
Correct |
5 ms |
2168 KB |
Output is correct |
23 |
Correct |
4 ms |
1656 KB |
Output is correct |
24 |
Correct |
6 ms |
2652 KB |
Output is correct |
25 |
Correct |
6 ms |
2808 KB |
Output is correct |
26 |
Correct |
6 ms |
2812 KB |
Output is correct |
27 |
Correct |
6 ms |
2680 KB |
Output is correct |
28 |
Correct |
6 ms |
2808 KB |
Output is correct |
29 |
Correct |
6 ms |
2808 KB |
Output is correct |
30 |
Correct |
5 ms |
2808 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
380 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
348 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
380 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
3 ms |
376 KB |
Output is correct |
17 |
Correct |
5 ms |
2552 KB |
Output is correct |
18 |
Correct |
7 ms |
2680 KB |
Output is correct |
19 |
Correct |
5 ms |
1912 KB |
Output is correct |
20 |
Correct |
12 ms |
2808 KB |
Output is correct |
21 |
Correct |
6 ms |
2680 KB |
Output is correct |
22 |
Correct |
5 ms |
2168 KB |
Output is correct |
23 |
Correct |
4 ms |
1656 KB |
Output is correct |
24 |
Correct |
6 ms |
2652 KB |
Output is correct |
25 |
Correct |
6 ms |
2808 KB |
Output is correct |
26 |
Correct |
6 ms |
2812 KB |
Output is correct |
27 |
Correct |
6 ms |
2680 KB |
Output is correct |
28 |
Correct |
6 ms |
2808 KB |
Output is correct |
29 |
Correct |
6 ms |
2808 KB |
Output is correct |
30 |
Correct |
5 ms |
2808 KB |
Output is correct |
31 |
Correct |
28 ms |
504 KB |
Output is correct |
32 |
Correct |
54 ms |
22500 KB |
Output is correct |
33 |
Correct |
67 ms |
27680 KB |
Output is correct |
34 |
Correct |
45 ms |
18680 KB |
Output is correct |
35 |
Correct |
65 ms |
28024 KB |
Output is correct |
36 |
Correct |
84 ms |
27384 KB |
Output is correct |
37 |
Correct |
53 ms |
21624 KB |
Output is correct |
38 |
Correct |
36 ms |
15744 KB |
Output is correct |
39 |
Correct |
78 ms |
27356 KB |
Output is correct |
40 |
Correct |
65 ms |
27384 KB |
Output is correct |
41 |
Correct |
76 ms |
28024 KB |
Output is correct |
42 |
Correct |
55 ms |
25588 KB |
Output is correct |
43 |
Correct |
86 ms |
25208 KB |
Output is correct |
44 |
Correct |
64 ms |
28024 KB |
Output is correct |
45 |
Correct |
58 ms |
27896 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
380 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
348 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
380 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
3 ms |
376 KB |
Output is correct |
17 |
Correct |
5 ms |
2552 KB |
Output is correct |
18 |
Correct |
7 ms |
2680 KB |
Output is correct |
19 |
Correct |
5 ms |
1912 KB |
Output is correct |
20 |
Correct |
12 ms |
2808 KB |
Output is correct |
21 |
Correct |
6 ms |
2680 KB |
Output is correct |
22 |
Correct |
5 ms |
2168 KB |
Output is correct |
23 |
Correct |
4 ms |
1656 KB |
Output is correct |
24 |
Correct |
6 ms |
2652 KB |
Output is correct |
25 |
Correct |
6 ms |
2808 KB |
Output is correct |
26 |
Correct |
6 ms |
2812 KB |
Output is correct |
27 |
Correct |
6 ms |
2680 KB |
Output is correct |
28 |
Correct |
6 ms |
2808 KB |
Output is correct |
29 |
Correct |
6 ms |
2808 KB |
Output is correct |
30 |
Correct |
5 ms |
2808 KB |
Output is correct |
31 |
Correct |
28 ms |
504 KB |
Output is correct |
32 |
Correct |
54 ms |
22500 KB |
Output is correct |
33 |
Correct |
67 ms |
27680 KB |
Output is correct |
34 |
Correct |
45 ms |
18680 KB |
Output is correct |
35 |
Correct |
65 ms |
28024 KB |
Output is correct |
36 |
Correct |
84 ms |
27384 KB |
Output is correct |
37 |
Correct |
53 ms |
21624 KB |
Output is correct |
38 |
Correct |
36 ms |
15744 KB |
Output is correct |
39 |
Correct |
78 ms |
27356 KB |
Output is correct |
40 |
Correct |
65 ms |
27384 KB |
Output is correct |
41 |
Correct |
76 ms |
28024 KB |
Output is correct |
42 |
Correct |
55 ms |
25588 KB |
Output is correct |
43 |
Correct |
86 ms |
25208 KB |
Output is correct |
44 |
Correct |
64 ms |
28024 KB |
Output is correct |
45 |
Correct |
58 ms |
27896 KB |
Output is correct |
46 |
Correct |
4 ms |
376 KB |
Output is correct |
47 |
Incorrect |
17 ms |
380 KB |
Output isn't correct |
48 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
380 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
348 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
380 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
3 ms |
376 KB |
Output is correct |
17 |
Correct |
5 ms |
2552 KB |
Output is correct |
18 |
Correct |
7 ms |
2680 KB |
Output is correct |
19 |
Correct |
5 ms |
1912 KB |
Output is correct |
20 |
Correct |
12 ms |
2808 KB |
Output is correct |
21 |
Correct |
6 ms |
2680 KB |
Output is correct |
22 |
Correct |
5 ms |
2168 KB |
Output is correct |
23 |
Correct |
4 ms |
1656 KB |
Output is correct |
24 |
Correct |
6 ms |
2652 KB |
Output is correct |
25 |
Correct |
6 ms |
2808 KB |
Output is correct |
26 |
Correct |
6 ms |
2812 KB |
Output is correct |
27 |
Correct |
6 ms |
2680 KB |
Output is correct |
28 |
Correct |
6 ms |
2808 KB |
Output is correct |
29 |
Correct |
6 ms |
2808 KB |
Output is correct |
30 |
Correct |
5 ms |
2808 KB |
Output is correct |
31 |
Correct |
28 ms |
504 KB |
Output is correct |
32 |
Correct |
54 ms |
22500 KB |
Output is correct |
33 |
Correct |
67 ms |
27680 KB |
Output is correct |
34 |
Correct |
45 ms |
18680 KB |
Output is correct |
35 |
Correct |
65 ms |
28024 KB |
Output is correct |
36 |
Correct |
84 ms |
27384 KB |
Output is correct |
37 |
Correct |
53 ms |
21624 KB |
Output is correct |
38 |
Correct |
36 ms |
15744 KB |
Output is correct |
39 |
Correct |
78 ms |
27356 KB |
Output is correct |
40 |
Correct |
65 ms |
27384 KB |
Output is correct |
41 |
Correct |
76 ms |
28024 KB |
Output is correct |
42 |
Correct |
55 ms |
25588 KB |
Output is correct |
43 |
Correct |
86 ms |
25208 KB |
Output is correct |
44 |
Correct |
64 ms |
28024 KB |
Output is correct |
45 |
Correct |
58 ms |
27896 KB |
Output is correct |
46 |
Correct |
4 ms |
376 KB |
Output is correct |
47 |
Incorrect |
17 ms |
380 KB |
Output isn't correct |
48 |
Halted |
0 ms |
0 KB |
- |