#include <iostream>
#include <string>
#include <unordered_map>
#include <cstring>
#include <chrono>
#include <vector>
#include <map>
#include <random>
#include <set>
#include <algorithm>
#include <math.h>
#include <cstdio>
#include <stdio.h>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <deque>
#include <cassert>
#include <stack>
using namespace std;
#define int long long
const int inf = 2e9;
const int mod = 1e9 + 7;
const int N = 5e5 + 15;
int n, m, a[N], p[N], maxp[N], dp[N], sumback[N];
main() {
ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0);
cin >> n;
for(int i = 1; i <= n; ++i) {
cin >> a[i];
p[i] = p[i-1] + a[i];
maxp[i] = max(maxp[i-1], p[i]);
}
for(int i = 1; i <= n; ++i) {
dp[i] = 1;
for(int f = 0; f < i; ++f)
for(int l = f + 1; l < i; ++l)
if(2 * p[l] - p[sumback[l]] <= p[i]) {
if(dp[l] + 1 >= dp[i])
sumback[i] = max(sumback[i], l);
dp[i] = max(dp[i], dp[l] + 1);
}
}
cout << dp[n] << endl;
return 0;
}
Compilation message
segments.cpp:29:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main() {
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 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 |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 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 |
380 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 |
376 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 |
376 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 |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 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 |
380 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 |
376 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 |
23 ms |
376 KB |
Output is correct |
17 |
Correct |
43 ms |
376 KB |
Output is correct |
18 |
Correct |
48 ms |
376 KB |
Output is correct |
19 |
Correct |
45 ms |
376 KB |
Output is correct |
20 |
Correct |
50 ms |
376 KB |
Output is correct |
21 |
Correct |
49 ms |
504 KB |
Output is correct |
22 |
Correct |
26 ms |
376 KB |
Output is correct |
23 |
Correct |
12 ms |
376 KB |
Output is correct |
24 |
Correct |
49 ms |
376 KB |
Output is correct |
25 |
Correct |
49 ms |
376 KB |
Output is correct |
26 |
Correct |
51 ms |
376 KB |
Output is correct |
27 |
Correct |
34 ms |
376 KB |
Output is correct |
28 |
Correct |
50 ms |
424 KB |
Output is correct |
29 |
Correct |
50 ms |
476 KB |
Output is correct |
30 |
Correct |
50 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 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 |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 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 |
380 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 |
376 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 |
23 ms |
376 KB |
Output is correct |
17 |
Correct |
43 ms |
376 KB |
Output is correct |
18 |
Correct |
48 ms |
376 KB |
Output is correct |
19 |
Correct |
45 ms |
376 KB |
Output is correct |
20 |
Correct |
50 ms |
376 KB |
Output is correct |
21 |
Correct |
49 ms |
504 KB |
Output is correct |
22 |
Correct |
26 ms |
376 KB |
Output is correct |
23 |
Correct |
12 ms |
376 KB |
Output is correct |
24 |
Correct |
49 ms |
376 KB |
Output is correct |
25 |
Correct |
49 ms |
376 KB |
Output is correct |
26 |
Correct |
51 ms |
376 KB |
Output is correct |
27 |
Correct |
34 ms |
376 KB |
Output is correct |
28 |
Correct |
50 ms |
424 KB |
Output is correct |
29 |
Correct |
50 ms |
476 KB |
Output is correct |
30 |
Correct |
50 ms |
384 KB |
Output is correct |
31 |
Execution timed out |
1556 ms |
760 KB |
Time limit exceeded |
32 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 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 |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 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 |
380 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 |
376 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 |
23 ms |
376 KB |
Output is correct |
17 |
Correct |
43 ms |
376 KB |
Output is correct |
18 |
Correct |
48 ms |
376 KB |
Output is correct |
19 |
Correct |
45 ms |
376 KB |
Output is correct |
20 |
Correct |
50 ms |
376 KB |
Output is correct |
21 |
Correct |
49 ms |
504 KB |
Output is correct |
22 |
Correct |
26 ms |
376 KB |
Output is correct |
23 |
Correct |
12 ms |
376 KB |
Output is correct |
24 |
Correct |
49 ms |
376 KB |
Output is correct |
25 |
Correct |
49 ms |
376 KB |
Output is correct |
26 |
Correct |
51 ms |
376 KB |
Output is correct |
27 |
Correct |
34 ms |
376 KB |
Output is correct |
28 |
Correct |
50 ms |
424 KB |
Output is correct |
29 |
Correct |
50 ms |
476 KB |
Output is correct |
30 |
Correct |
50 ms |
384 KB |
Output is correct |
31 |
Execution timed out |
1556 ms |
760 KB |
Time limit exceeded |
32 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 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 |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 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 |
380 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 |
376 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 |
23 ms |
376 KB |
Output is correct |
17 |
Correct |
43 ms |
376 KB |
Output is correct |
18 |
Correct |
48 ms |
376 KB |
Output is correct |
19 |
Correct |
45 ms |
376 KB |
Output is correct |
20 |
Correct |
50 ms |
376 KB |
Output is correct |
21 |
Correct |
49 ms |
504 KB |
Output is correct |
22 |
Correct |
26 ms |
376 KB |
Output is correct |
23 |
Correct |
12 ms |
376 KB |
Output is correct |
24 |
Correct |
49 ms |
376 KB |
Output is correct |
25 |
Correct |
49 ms |
376 KB |
Output is correct |
26 |
Correct |
51 ms |
376 KB |
Output is correct |
27 |
Correct |
34 ms |
376 KB |
Output is correct |
28 |
Correct |
50 ms |
424 KB |
Output is correct |
29 |
Correct |
50 ms |
476 KB |
Output is correct |
30 |
Correct |
50 ms |
384 KB |
Output is correct |
31 |
Execution timed out |
1556 ms |
760 KB |
Time limit exceeded |
32 |
Halted |
0 ms |
0 KB |
- |