#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
#define p(x,y) pair<ll,ll>(x,y)
#define BIT(i,x) ((x>>i)&1)
#define MASK(x) (1<<x)
#define ld long double
#define __builtin_popcount __builtin_popcountll
#define pll pair<ll,ll>
#define kt cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n"
template<class T1,class T2>
bool maximize(T1 &x,T2 y)
{
if(x<y)
{
x=y;
return 1;
}
return 0;
}
template<class T1,class T2>
bool minimize(T1 &x,T2 y)
{
if(y<x)
{
x=y;
return 1;
}
return 0;
}
const ll M=1e9+7;
template <class T1,class T2>
void add(T1 &x,T2 y)
{
x+=y;
if(x>=M) x-=M;
}
template <class T1,class T2>
void sub(T1 &x, T2 y)
{
x-=y;
if(x<0) x+=M;
}
void online()
{
std::ios_base::sync_with_stdio(0);
cin.tie(0);
#ifdef thuc
freopen("input.inp","r",stdin);
freopen("output.out","w",stdout);
#else
#endif // thuc
}
const ll N=5e5+10,S=400;
ll n,a[N],f[N];
map<ll,ll> dp[N];
int main()
{
online();
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>a[i];
a[i]+=a[i-1];
}
ll ans=1;
dp[1][1]=1;
f[1]=1;
for(int i=1;i<=n;i++)
{
for(int j=f[i];j>=f[i]-1;j--)
{
if(j==0) continue;
maximize(dp[i+1][j],dp[i][j]);
maximize(f[i+1],j);
ll z=a[i]-a[dp[i][j]-1];
ll nxt=lower_bound(a+1,a+n+1,a[i]+z)-a;
maximize(dp[nxt][j+1],i+1);
maximize(f[nxt],j+1);
}
}
cout<<f[n];
kt;
}
Compilation message
segments.cpp: In function 'int main()':
segments.cpp:68:8: warning: unused variable 'ans' [-Wunused-variable]
68 | ll ans=1;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
27228 KB |
Output is correct |
2 |
Correct |
5 ms |
27248 KB |
Output is correct |
3 |
Correct |
5 ms |
27224 KB |
Output is correct |
4 |
Correct |
6 ms |
27272 KB |
Output is correct |
5 |
Correct |
6 ms |
27256 KB |
Output is correct |
6 |
Correct |
6 ms |
27244 KB |
Output is correct |
7 |
Correct |
6 ms |
27228 KB |
Output is correct |
8 |
Correct |
5 ms |
27228 KB |
Output is correct |
9 |
Correct |
6 ms |
27228 KB |
Output is correct |
10 |
Correct |
5 ms |
27304 KB |
Output is correct |
11 |
Correct |
5 ms |
27224 KB |
Output is correct |
12 |
Correct |
6 ms |
27224 KB |
Output is correct |
13 |
Correct |
5 ms |
27224 KB |
Output is correct |
14 |
Correct |
6 ms |
27228 KB |
Output is correct |
15 |
Correct |
6 ms |
27228 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
27228 KB |
Output is correct |
2 |
Correct |
5 ms |
27248 KB |
Output is correct |
3 |
Correct |
5 ms |
27224 KB |
Output is correct |
4 |
Correct |
6 ms |
27272 KB |
Output is correct |
5 |
Correct |
6 ms |
27256 KB |
Output is correct |
6 |
Correct |
6 ms |
27244 KB |
Output is correct |
7 |
Correct |
6 ms |
27228 KB |
Output is correct |
8 |
Correct |
5 ms |
27228 KB |
Output is correct |
9 |
Correct |
6 ms |
27228 KB |
Output is correct |
10 |
Correct |
5 ms |
27304 KB |
Output is correct |
11 |
Correct |
5 ms |
27224 KB |
Output is correct |
12 |
Correct |
6 ms |
27224 KB |
Output is correct |
13 |
Correct |
5 ms |
27224 KB |
Output is correct |
14 |
Correct |
6 ms |
27228 KB |
Output is correct |
15 |
Correct |
6 ms |
27228 KB |
Output is correct |
16 |
Correct |
5 ms |
27224 KB |
Output is correct |
17 |
Correct |
7 ms |
27224 KB |
Output is correct |
18 |
Correct |
5 ms |
27224 KB |
Output is correct |
19 |
Correct |
5 ms |
27228 KB |
Output is correct |
20 |
Correct |
5 ms |
27224 KB |
Output is correct |
21 |
Correct |
5 ms |
27228 KB |
Output is correct |
22 |
Correct |
5 ms |
27228 KB |
Output is correct |
23 |
Correct |
6 ms |
27304 KB |
Output is correct |
24 |
Correct |
6 ms |
27228 KB |
Output is correct |
25 |
Correct |
5 ms |
27228 KB |
Output is correct |
26 |
Correct |
6 ms |
27228 KB |
Output is correct |
27 |
Correct |
5 ms |
27228 KB |
Output is correct |
28 |
Correct |
5 ms |
27228 KB |
Output is correct |
29 |
Correct |
6 ms |
27228 KB |
Output is correct |
30 |
Correct |
6 ms |
27228 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
27228 KB |
Output is correct |
2 |
Correct |
5 ms |
27248 KB |
Output is correct |
3 |
Correct |
5 ms |
27224 KB |
Output is correct |
4 |
Correct |
6 ms |
27272 KB |
Output is correct |
5 |
Correct |
6 ms |
27256 KB |
Output is correct |
6 |
Correct |
6 ms |
27244 KB |
Output is correct |
7 |
Correct |
6 ms |
27228 KB |
Output is correct |
8 |
Correct |
5 ms |
27228 KB |
Output is correct |
9 |
Correct |
6 ms |
27228 KB |
Output is correct |
10 |
Correct |
5 ms |
27304 KB |
Output is correct |
11 |
Correct |
5 ms |
27224 KB |
Output is correct |
12 |
Correct |
6 ms |
27224 KB |
Output is correct |
13 |
Correct |
5 ms |
27224 KB |
Output is correct |
14 |
Correct |
6 ms |
27228 KB |
Output is correct |
15 |
Correct |
6 ms |
27228 KB |
Output is correct |
16 |
Correct |
5 ms |
27224 KB |
Output is correct |
17 |
Correct |
7 ms |
27224 KB |
Output is correct |
18 |
Correct |
5 ms |
27224 KB |
Output is correct |
19 |
Correct |
5 ms |
27228 KB |
Output is correct |
20 |
Correct |
5 ms |
27224 KB |
Output is correct |
21 |
Correct |
5 ms |
27228 KB |
Output is correct |
22 |
Correct |
5 ms |
27228 KB |
Output is correct |
23 |
Correct |
6 ms |
27304 KB |
Output is correct |
24 |
Correct |
6 ms |
27228 KB |
Output is correct |
25 |
Correct |
5 ms |
27228 KB |
Output is correct |
26 |
Correct |
6 ms |
27228 KB |
Output is correct |
27 |
Correct |
5 ms |
27228 KB |
Output is correct |
28 |
Correct |
5 ms |
27228 KB |
Output is correct |
29 |
Correct |
6 ms |
27228 KB |
Output is correct |
30 |
Correct |
6 ms |
27228 KB |
Output is correct |
31 |
Correct |
6 ms |
27484 KB |
Output is correct |
32 |
Correct |
6 ms |
27560 KB |
Output is correct |
33 |
Correct |
6 ms |
27740 KB |
Output is correct |
34 |
Correct |
6 ms |
27740 KB |
Output is correct |
35 |
Correct |
9 ms |
27744 KB |
Output is correct |
36 |
Correct |
6 ms |
27484 KB |
Output is correct |
37 |
Correct |
6 ms |
27484 KB |
Output is correct |
38 |
Correct |
6 ms |
27572 KB |
Output is correct |
39 |
Correct |
6 ms |
27564 KB |
Output is correct |
40 |
Correct |
7 ms |
27740 KB |
Output is correct |
41 |
Correct |
6 ms |
27740 KB |
Output is correct |
42 |
Correct |
7 ms |
27740 KB |
Output is correct |
43 |
Correct |
8 ms |
27740 KB |
Output is correct |
44 |
Correct |
6 ms |
27840 KB |
Output is correct |
45 |
Correct |
6 ms |
27740 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
27228 KB |
Output is correct |
2 |
Correct |
5 ms |
27248 KB |
Output is correct |
3 |
Correct |
5 ms |
27224 KB |
Output is correct |
4 |
Correct |
6 ms |
27272 KB |
Output is correct |
5 |
Correct |
6 ms |
27256 KB |
Output is correct |
6 |
Correct |
6 ms |
27244 KB |
Output is correct |
7 |
Correct |
6 ms |
27228 KB |
Output is correct |
8 |
Correct |
5 ms |
27228 KB |
Output is correct |
9 |
Correct |
6 ms |
27228 KB |
Output is correct |
10 |
Correct |
5 ms |
27304 KB |
Output is correct |
11 |
Correct |
5 ms |
27224 KB |
Output is correct |
12 |
Correct |
6 ms |
27224 KB |
Output is correct |
13 |
Correct |
5 ms |
27224 KB |
Output is correct |
14 |
Correct |
6 ms |
27228 KB |
Output is correct |
15 |
Correct |
6 ms |
27228 KB |
Output is correct |
16 |
Correct |
5 ms |
27224 KB |
Output is correct |
17 |
Correct |
7 ms |
27224 KB |
Output is correct |
18 |
Correct |
5 ms |
27224 KB |
Output is correct |
19 |
Correct |
5 ms |
27228 KB |
Output is correct |
20 |
Correct |
5 ms |
27224 KB |
Output is correct |
21 |
Correct |
5 ms |
27228 KB |
Output is correct |
22 |
Correct |
5 ms |
27228 KB |
Output is correct |
23 |
Correct |
6 ms |
27304 KB |
Output is correct |
24 |
Correct |
6 ms |
27228 KB |
Output is correct |
25 |
Correct |
5 ms |
27228 KB |
Output is correct |
26 |
Correct |
6 ms |
27228 KB |
Output is correct |
27 |
Correct |
5 ms |
27228 KB |
Output is correct |
28 |
Correct |
5 ms |
27228 KB |
Output is correct |
29 |
Correct |
6 ms |
27228 KB |
Output is correct |
30 |
Correct |
6 ms |
27228 KB |
Output is correct |
31 |
Correct |
6 ms |
27484 KB |
Output is correct |
32 |
Correct |
6 ms |
27560 KB |
Output is correct |
33 |
Correct |
6 ms |
27740 KB |
Output is correct |
34 |
Correct |
6 ms |
27740 KB |
Output is correct |
35 |
Correct |
9 ms |
27744 KB |
Output is correct |
36 |
Correct |
6 ms |
27484 KB |
Output is correct |
37 |
Correct |
6 ms |
27484 KB |
Output is correct |
38 |
Correct |
6 ms |
27572 KB |
Output is correct |
39 |
Correct |
6 ms |
27564 KB |
Output is correct |
40 |
Correct |
7 ms |
27740 KB |
Output is correct |
41 |
Correct |
6 ms |
27740 KB |
Output is correct |
42 |
Correct |
7 ms |
27740 KB |
Output is correct |
43 |
Correct |
8 ms |
27740 KB |
Output is correct |
44 |
Correct |
6 ms |
27840 KB |
Output is correct |
45 |
Correct |
6 ms |
27740 KB |
Output is correct |
46 |
Correct |
21 ms |
33884 KB |
Output is correct |
47 |
Correct |
35 ms |
41604 KB |
Output is correct |
48 |
Correct |
55 ms |
43928 KB |
Output is correct |
49 |
Correct |
43 ms |
46312 KB |
Output is correct |
50 |
Correct |
42 ms |
47180 KB |
Output is correct |
51 |
Correct |
42 ms |
40784 KB |
Output is correct |
52 |
Correct |
24 ms |
33880 KB |
Output is correct |
53 |
Correct |
17 ms |
31324 KB |
Output is correct |
54 |
Correct |
41 ms |
40364 KB |
Output is correct |
55 |
Correct |
39 ms |
40788 KB |
Output is correct |
56 |
Correct |
48 ms |
46416 KB |
Output is correct |
57 |
Correct |
35 ms |
43868 KB |
Output is correct |
58 |
Correct |
37 ms |
44368 KB |
Output is correct |
59 |
Correct |
39 ms |
46420 KB |
Output is correct |
60 |
Correct |
36 ms |
42580 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
27228 KB |
Output is correct |
2 |
Correct |
5 ms |
27248 KB |
Output is correct |
3 |
Correct |
5 ms |
27224 KB |
Output is correct |
4 |
Correct |
6 ms |
27272 KB |
Output is correct |
5 |
Correct |
6 ms |
27256 KB |
Output is correct |
6 |
Correct |
6 ms |
27244 KB |
Output is correct |
7 |
Correct |
6 ms |
27228 KB |
Output is correct |
8 |
Correct |
5 ms |
27228 KB |
Output is correct |
9 |
Correct |
6 ms |
27228 KB |
Output is correct |
10 |
Correct |
5 ms |
27304 KB |
Output is correct |
11 |
Correct |
5 ms |
27224 KB |
Output is correct |
12 |
Correct |
6 ms |
27224 KB |
Output is correct |
13 |
Correct |
5 ms |
27224 KB |
Output is correct |
14 |
Correct |
6 ms |
27228 KB |
Output is correct |
15 |
Correct |
6 ms |
27228 KB |
Output is correct |
16 |
Correct |
5 ms |
27224 KB |
Output is correct |
17 |
Correct |
7 ms |
27224 KB |
Output is correct |
18 |
Correct |
5 ms |
27224 KB |
Output is correct |
19 |
Correct |
5 ms |
27228 KB |
Output is correct |
20 |
Correct |
5 ms |
27224 KB |
Output is correct |
21 |
Correct |
5 ms |
27228 KB |
Output is correct |
22 |
Correct |
5 ms |
27228 KB |
Output is correct |
23 |
Correct |
6 ms |
27304 KB |
Output is correct |
24 |
Correct |
6 ms |
27228 KB |
Output is correct |
25 |
Correct |
5 ms |
27228 KB |
Output is correct |
26 |
Correct |
6 ms |
27228 KB |
Output is correct |
27 |
Correct |
5 ms |
27228 KB |
Output is correct |
28 |
Correct |
5 ms |
27228 KB |
Output is correct |
29 |
Correct |
6 ms |
27228 KB |
Output is correct |
30 |
Correct |
6 ms |
27228 KB |
Output is correct |
31 |
Correct |
6 ms |
27484 KB |
Output is correct |
32 |
Correct |
6 ms |
27560 KB |
Output is correct |
33 |
Correct |
6 ms |
27740 KB |
Output is correct |
34 |
Correct |
6 ms |
27740 KB |
Output is correct |
35 |
Correct |
9 ms |
27744 KB |
Output is correct |
36 |
Correct |
6 ms |
27484 KB |
Output is correct |
37 |
Correct |
6 ms |
27484 KB |
Output is correct |
38 |
Correct |
6 ms |
27572 KB |
Output is correct |
39 |
Correct |
6 ms |
27564 KB |
Output is correct |
40 |
Correct |
7 ms |
27740 KB |
Output is correct |
41 |
Correct |
6 ms |
27740 KB |
Output is correct |
42 |
Correct |
7 ms |
27740 KB |
Output is correct |
43 |
Correct |
8 ms |
27740 KB |
Output is correct |
44 |
Correct |
6 ms |
27840 KB |
Output is correct |
45 |
Correct |
6 ms |
27740 KB |
Output is correct |
46 |
Correct |
21 ms |
33884 KB |
Output is correct |
47 |
Correct |
35 ms |
41604 KB |
Output is correct |
48 |
Correct |
55 ms |
43928 KB |
Output is correct |
49 |
Correct |
43 ms |
46312 KB |
Output is correct |
50 |
Correct |
42 ms |
47180 KB |
Output is correct |
51 |
Correct |
42 ms |
40784 KB |
Output is correct |
52 |
Correct |
24 ms |
33880 KB |
Output is correct |
53 |
Correct |
17 ms |
31324 KB |
Output is correct |
54 |
Correct |
41 ms |
40364 KB |
Output is correct |
55 |
Correct |
39 ms |
40788 KB |
Output is correct |
56 |
Correct |
48 ms |
46416 KB |
Output is correct |
57 |
Correct |
35 ms |
43868 KB |
Output is correct |
58 |
Correct |
37 ms |
44368 KB |
Output is correct |
59 |
Correct |
39 ms |
46420 KB |
Output is correct |
60 |
Correct |
36 ms |
42580 KB |
Output is correct |
61 |
Correct |
93 ms |
64852 KB |
Output is correct |
62 |
Correct |
115 ms |
80620 KB |
Output is correct |
63 |
Correct |
193 ms |
103764 KB |
Output is correct |
64 |
Correct |
226 ms |
124508 KB |
Output is correct |
65 |
Correct |
214 ms |
130488 KB |
Output is correct |
66 |
Correct |
203 ms |
99356 KB |
Output is correct |
67 |
Correct |
173 ms |
85520 KB |
Output is correct |
68 |
Correct |
80 ms |
56544 KB |
Output is correct |
69 |
Correct |
176 ms |
95568 KB |
Output is correct |
70 |
Correct |
179 ms |
99412 KB |
Output is correct |
71 |
Correct |
198 ms |
127520 KB |
Output is correct |
72 |
Correct |
156 ms |
115488 KB |
Output is correct |
73 |
Correct |
177 ms |
123832 KB |
Output is correct |
74 |
Correct |
180 ms |
128852 KB |
Output is correct |
75 |
Correct |
179 ms |
122452 KB |
Output is correct |