#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define PI acos(-1)
#define ld long double
const int mod = 1e9+7, N = 100005, inf = 1e18;
int msb(int val){return sizeof(int)*8-__builtin_clzll(val);}
int a[N], n, m, k;
vector<pii> dp[N];
int pr[N];
vector<int> pm[N];
void solve(int test_case){
int i, j;
cin >> n;
for(i=1;i<=n;i++){
cin >> a[i];
pr[i]=a[i];pr[i]+=pr[i-1];
}
for(i=1;i<=n;i++){
dp[i].pb({pr[i], 1});
dp[i].pb({inf, -213234684});
pm[i].pb(dp[i][0].ss);
for(j=1;j<dp[i].size();j++)pm[i].pb(max(pm[i].back(), dp[i][j].ss));
}
for(i=2;i<=n;i++){
for(j=1;j<i;j++){
int s = pr[i]-pr[j];
int pos = upper_bound(all(dp[j]), pii{s+1,-1})-dp[j].begin();pos--;
if(pos<0)continue;
int mx = pm[j][pos];
dp[i].pb({s, mx+1});
}sort(all(dp[i]));
pm[i].clear();
pm[i].pb(dp[i][0].ss);
for(j=1;j<dp[i].size();j++)pm[i].pb(max(pm[i].back(), dp[i][j].ss));
}
int ans = 1;
for(auto [x, y] : dp[n]){
ans = max(ans, y);
}
cout << ans << '\n';
return;
}
signed main(){
FASTIO;
#define MULTITEST 0
#if MULTITEST
int ___T;
cin >> ___T;
for(int T_CASE = 1; T_CASE <= ___T; T_CASE++)
solve(T_CASE);
#else
solve(1);
#endif
return 0;
}
Compilation message
segments.cpp: In function 'void solve(long long int)':
segments.cpp:29:12: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
29 | for(j=1;j<dp[i].size();j++)pm[i].pb(max(pm[i].back(), dp[i][j].ss));
| ~^~~~~~~~~~~~~
segments.cpp:41:12: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
41 | for(j=1;j<dp[i].size();j++)pm[i].pb(max(pm[i].back(), dp[i][j].ss));
| ~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
5100 KB |
Output is correct |
2 |
Correct |
3 ms |
5100 KB |
Output is correct |
3 |
Correct |
3 ms |
5100 KB |
Output is correct |
4 |
Correct |
4 ms |
5100 KB |
Output is correct |
5 |
Correct |
3 ms |
5100 KB |
Output is correct |
6 |
Correct |
3 ms |
5100 KB |
Output is correct |
7 |
Correct |
3 ms |
5100 KB |
Output is correct |
8 |
Correct |
3 ms |
5100 KB |
Output is correct |
9 |
Correct |
3 ms |
5100 KB |
Output is correct |
10 |
Correct |
3 ms |
5100 KB |
Output is correct |
11 |
Correct |
3 ms |
5100 KB |
Output is correct |
12 |
Correct |
3 ms |
5100 KB |
Output is correct |
13 |
Correct |
3 ms |
5100 KB |
Output is correct |
14 |
Correct |
3 ms |
5100 KB |
Output is correct |
15 |
Correct |
3 ms |
5100 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
5100 KB |
Output is correct |
2 |
Correct |
3 ms |
5100 KB |
Output is correct |
3 |
Correct |
3 ms |
5100 KB |
Output is correct |
4 |
Correct |
4 ms |
5100 KB |
Output is correct |
5 |
Correct |
3 ms |
5100 KB |
Output is correct |
6 |
Correct |
3 ms |
5100 KB |
Output is correct |
7 |
Correct |
3 ms |
5100 KB |
Output is correct |
8 |
Correct |
3 ms |
5100 KB |
Output is correct |
9 |
Correct |
3 ms |
5100 KB |
Output is correct |
10 |
Correct |
3 ms |
5100 KB |
Output is correct |
11 |
Correct |
3 ms |
5100 KB |
Output is correct |
12 |
Correct |
3 ms |
5100 KB |
Output is correct |
13 |
Correct |
3 ms |
5100 KB |
Output is correct |
14 |
Correct |
3 ms |
5100 KB |
Output is correct |
15 |
Correct |
3 ms |
5100 KB |
Output is correct |
16 |
Correct |
4 ms |
5100 KB |
Output is correct |
17 |
Correct |
11 ms |
8428 KB |
Output is correct |
18 |
Correct |
13 ms |
8940 KB |
Output is correct |
19 |
Correct |
12 ms |
9068 KB |
Output is correct |
20 |
Correct |
12 ms |
9068 KB |
Output is correct |
21 |
Correct |
13 ms |
8940 KB |
Output is correct |
22 |
Correct |
9 ms |
7660 KB |
Output is correct |
23 |
Correct |
7 ms |
6380 KB |
Output is correct |
24 |
Correct |
14 ms |
8960 KB |
Output is correct |
25 |
Correct |
13 ms |
8940 KB |
Output is correct |
26 |
Correct |
12 ms |
9068 KB |
Output is correct |
27 |
Correct |
10 ms |
7788 KB |
Output is correct |
28 |
Correct |
13 ms |
8960 KB |
Output is correct |
29 |
Correct |
13 ms |
9068 KB |
Output is correct |
30 |
Correct |
13 ms |
9068 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
5100 KB |
Output is correct |
2 |
Correct |
3 ms |
5100 KB |
Output is correct |
3 |
Correct |
3 ms |
5100 KB |
Output is correct |
4 |
Correct |
4 ms |
5100 KB |
Output is correct |
5 |
Correct |
3 ms |
5100 KB |
Output is correct |
6 |
Correct |
3 ms |
5100 KB |
Output is correct |
7 |
Correct |
3 ms |
5100 KB |
Output is correct |
8 |
Correct |
3 ms |
5100 KB |
Output is correct |
9 |
Correct |
3 ms |
5100 KB |
Output is correct |
10 |
Correct |
3 ms |
5100 KB |
Output is correct |
11 |
Correct |
3 ms |
5100 KB |
Output is correct |
12 |
Correct |
3 ms |
5100 KB |
Output is correct |
13 |
Correct |
3 ms |
5100 KB |
Output is correct |
14 |
Correct |
3 ms |
5100 KB |
Output is correct |
15 |
Correct |
3 ms |
5100 KB |
Output is correct |
16 |
Correct |
4 ms |
5100 KB |
Output is correct |
17 |
Correct |
11 ms |
8428 KB |
Output is correct |
18 |
Correct |
13 ms |
8940 KB |
Output is correct |
19 |
Correct |
12 ms |
9068 KB |
Output is correct |
20 |
Correct |
12 ms |
9068 KB |
Output is correct |
21 |
Correct |
13 ms |
8940 KB |
Output is correct |
22 |
Correct |
9 ms |
7660 KB |
Output is correct |
23 |
Correct |
7 ms |
6380 KB |
Output is correct |
24 |
Correct |
14 ms |
8960 KB |
Output is correct |
25 |
Correct |
13 ms |
8940 KB |
Output is correct |
26 |
Correct |
12 ms |
9068 KB |
Output is correct |
27 |
Correct |
10 ms |
7788 KB |
Output is correct |
28 |
Correct |
13 ms |
8960 KB |
Output is correct |
29 |
Correct |
13 ms |
9068 KB |
Output is correct |
30 |
Correct |
13 ms |
9068 KB |
Output is correct |
31 |
Correct |
21 ms |
5356 KB |
Output is correct |
32 |
Correct |
382 ms |
108396 KB |
Output is correct |
33 |
Correct |
512 ms |
135788 KB |
Output is correct |
34 |
Correct |
459 ms |
107628 KB |
Output is correct |
35 |
Correct |
522 ms |
137836 KB |
Output is correct |
36 |
Correct |
516 ms |
134848 KB |
Output is correct |
37 |
Correct |
341 ms |
95596 KB |
Output is correct |
38 |
Correct |
210 ms |
62188 KB |
Output is correct |
39 |
Correct |
535 ms |
135020 KB |
Output is correct |
40 |
Correct |
530 ms |
135148 KB |
Output is correct |
41 |
Correct |
523 ms |
137836 KB |
Output is correct |
42 |
Correct |
464 ms |
116844 KB |
Output is correct |
43 |
Correct |
469 ms |
112620 KB |
Output is correct |
44 |
Correct |
510 ms |
137964 KB |
Output is correct |
45 |
Correct |
520 ms |
137692 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
5100 KB |
Output is correct |
2 |
Correct |
3 ms |
5100 KB |
Output is correct |
3 |
Correct |
3 ms |
5100 KB |
Output is correct |
4 |
Correct |
4 ms |
5100 KB |
Output is correct |
5 |
Correct |
3 ms |
5100 KB |
Output is correct |
6 |
Correct |
3 ms |
5100 KB |
Output is correct |
7 |
Correct |
3 ms |
5100 KB |
Output is correct |
8 |
Correct |
3 ms |
5100 KB |
Output is correct |
9 |
Correct |
3 ms |
5100 KB |
Output is correct |
10 |
Correct |
3 ms |
5100 KB |
Output is correct |
11 |
Correct |
3 ms |
5100 KB |
Output is correct |
12 |
Correct |
3 ms |
5100 KB |
Output is correct |
13 |
Correct |
3 ms |
5100 KB |
Output is correct |
14 |
Correct |
3 ms |
5100 KB |
Output is correct |
15 |
Correct |
3 ms |
5100 KB |
Output is correct |
16 |
Correct |
4 ms |
5100 KB |
Output is correct |
17 |
Correct |
11 ms |
8428 KB |
Output is correct |
18 |
Correct |
13 ms |
8940 KB |
Output is correct |
19 |
Correct |
12 ms |
9068 KB |
Output is correct |
20 |
Correct |
12 ms |
9068 KB |
Output is correct |
21 |
Correct |
13 ms |
8940 KB |
Output is correct |
22 |
Correct |
9 ms |
7660 KB |
Output is correct |
23 |
Correct |
7 ms |
6380 KB |
Output is correct |
24 |
Correct |
14 ms |
8960 KB |
Output is correct |
25 |
Correct |
13 ms |
8940 KB |
Output is correct |
26 |
Correct |
12 ms |
9068 KB |
Output is correct |
27 |
Correct |
10 ms |
7788 KB |
Output is correct |
28 |
Correct |
13 ms |
8960 KB |
Output is correct |
29 |
Correct |
13 ms |
9068 KB |
Output is correct |
30 |
Correct |
13 ms |
9068 KB |
Output is correct |
31 |
Correct |
21 ms |
5356 KB |
Output is correct |
32 |
Correct |
382 ms |
108396 KB |
Output is correct |
33 |
Correct |
512 ms |
135788 KB |
Output is correct |
34 |
Correct |
459 ms |
107628 KB |
Output is correct |
35 |
Correct |
522 ms |
137836 KB |
Output is correct |
36 |
Correct |
516 ms |
134848 KB |
Output is correct |
37 |
Correct |
341 ms |
95596 KB |
Output is correct |
38 |
Correct |
210 ms |
62188 KB |
Output is correct |
39 |
Correct |
535 ms |
135020 KB |
Output is correct |
40 |
Correct |
530 ms |
135148 KB |
Output is correct |
41 |
Correct |
523 ms |
137836 KB |
Output is correct |
42 |
Correct |
464 ms |
116844 KB |
Output is correct |
43 |
Correct |
469 ms |
112620 KB |
Output is correct |
44 |
Correct |
510 ms |
137964 KB |
Output is correct |
45 |
Correct |
520 ms |
137692 KB |
Output is correct |
46 |
Execution timed out |
1588 ms |
14700 KB |
Time limit exceeded |
47 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
5100 KB |
Output is correct |
2 |
Correct |
3 ms |
5100 KB |
Output is correct |
3 |
Correct |
3 ms |
5100 KB |
Output is correct |
4 |
Correct |
4 ms |
5100 KB |
Output is correct |
5 |
Correct |
3 ms |
5100 KB |
Output is correct |
6 |
Correct |
3 ms |
5100 KB |
Output is correct |
7 |
Correct |
3 ms |
5100 KB |
Output is correct |
8 |
Correct |
3 ms |
5100 KB |
Output is correct |
9 |
Correct |
3 ms |
5100 KB |
Output is correct |
10 |
Correct |
3 ms |
5100 KB |
Output is correct |
11 |
Correct |
3 ms |
5100 KB |
Output is correct |
12 |
Correct |
3 ms |
5100 KB |
Output is correct |
13 |
Correct |
3 ms |
5100 KB |
Output is correct |
14 |
Correct |
3 ms |
5100 KB |
Output is correct |
15 |
Correct |
3 ms |
5100 KB |
Output is correct |
16 |
Correct |
4 ms |
5100 KB |
Output is correct |
17 |
Correct |
11 ms |
8428 KB |
Output is correct |
18 |
Correct |
13 ms |
8940 KB |
Output is correct |
19 |
Correct |
12 ms |
9068 KB |
Output is correct |
20 |
Correct |
12 ms |
9068 KB |
Output is correct |
21 |
Correct |
13 ms |
8940 KB |
Output is correct |
22 |
Correct |
9 ms |
7660 KB |
Output is correct |
23 |
Correct |
7 ms |
6380 KB |
Output is correct |
24 |
Correct |
14 ms |
8960 KB |
Output is correct |
25 |
Correct |
13 ms |
8940 KB |
Output is correct |
26 |
Correct |
12 ms |
9068 KB |
Output is correct |
27 |
Correct |
10 ms |
7788 KB |
Output is correct |
28 |
Correct |
13 ms |
8960 KB |
Output is correct |
29 |
Correct |
13 ms |
9068 KB |
Output is correct |
30 |
Correct |
13 ms |
9068 KB |
Output is correct |
31 |
Correct |
21 ms |
5356 KB |
Output is correct |
32 |
Correct |
382 ms |
108396 KB |
Output is correct |
33 |
Correct |
512 ms |
135788 KB |
Output is correct |
34 |
Correct |
459 ms |
107628 KB |
Output is correct |
35 |
Correct |
522 ms |
137836 KB |
Output is correct |
36 |
Correct |
516 ms |
134848 KB |
Output is correct |
37 |
Correct |
341 ms |
95596 KB |
Output is correct |
38 |
Correct |
210 ms |
62188 KB |
Output is correct |
39 |
Correct |
535 ms |
135020 KB |
Output is correct |
40 |
Correct |
530 ms |
135148 KB |
Output is correct |
41 |
Correct |
523 ms |
137836 KB |
Output is correct |
42 |
Correct |
464 ms |
116844 KB |
Output is correct |
43 |
Correct |
469 ms |
112620 KB |
Output is correct |
44 |
Correct |
510 ms |
137964 KB |
Output is correct |
45 |
Correct |
520 ms |
137692 KB |
Output is correct |
46 |
Execution timed out |
1588 ms |
14700 KB |
Time limit exceeded |
47 |
Halted |
0 ms |
0 KB |
- |