#include<bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
using namespace std;
const int N=5e5+5;
int n;
ll a[N];
map<int,int>dp[N];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>a[i];
a[i]+=a[i-1];
}
dp[1][0]=0;
for(int i=1;i<n;i++)
{
while(dp[i].size()>2) dp[i].erase(dp[i].begin());
for(auto&x:dp[i])
{
dp[i+1][x.fi]=max(dp[i+1][x.fi],x.se);
int v=lower_bound(a+1,a+n+1,2*a[i]-a[x.se])-a;
if(v<=n) dp[v][x.fi+1]=max(dp[v][x.fi+1],i);
}
}
while(dp[n].size()>1) dp[n].erase(dp[n].begin());
auto res=*dp[n].begin();
cout<<res.fi+1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
23788 KB |
Output is correct |
2 |
Correct |
16 ms |
23788 KB |
Output is correct |
3 |
Correct |
16 ms |
23788 KB |
Output is correct |
4 |
Correct |
16 ms |
23788 KB |
Output is correct |
5 |
Correct |
16 ms |
23788 KB |
Output is correct |
6 |
Correct |
16 ms |
23788 KB |
Output is correct |
7 |
Correct |
16 ms |
23916 KB |
Output is correct |
8 |
Correct |
16 ms |
23788 KB |
Output is correct |
9 |
Correct |
16 ms |
23788 KB |
Output is correct |
10 |
Correct |
16 ms |
23788 KB |
Output is correct |
11 |
Correct |
16 ms |
23780 KB |
Output is correct |
12 |
Correct |
16 ms |
23788 KB |
Output is correct |
13 |
Correct |
17 ms |
23788 KB |
Output is correct |
14 |
Correct |
16 ms |
23788 KB |
Output is correct |
15 |
Correct |
16 ms |
23788 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
23788 KB |
Output is correct |
2 |
Correct |
16 ms |
23788 KB |
Output is correct |
3 |
Correct |
16 ms |
23788 KB |
Output is correct |
4 |
Correct |
16 ms |
23788 KB |
Output is correct |
5 |
Correct |
16 ms |
23788 KB |
Output is correct |
6 |
Correct |
16 ms |
23788 KB |
Output is correct |
7 |
Correct |
16 ms |
23916 KB |
Output is correct |
8 |
Correct |
16 ms |
23788 KB |
Output is correct |
9 |
Correct |
16 ms |
23788 KB |
Output is correct |
10 |
Correct |
16 ms |
23788 KB |
Output is correct |
11 |
Correct |
16 ms |
23780 KB |
Output is correct |
12 |
Correct |
16 ms |
23788 KB |
Output is correct |
13 |
Correct |
17 ms |
23788 KB |
Output is correct |
14 |
Correct |
16 ms |
23788 KB |
Output is correct |
15 |
Correct |
16 ms |
23788 KB |
Output is correct |
16 |
Correct |
16 ms |
23788 KB |
Output is correct |
17 |
Correct |
16 ms |
23916 KB |
Output is correct |
18 |
Correct |
17 ms |
23916 KB |
Output is correct |
19 |
Correct |
18 ms |
23916 KB |
Output is correct |
20 |
Correct |
16 ms |
23916 KB |
Output is correct |
21 |
Correct |
16 ms |
23916 KB |
Output is correct |
22 |
Correct |
16 ms |
23916 KB |
Output is correct |
23 |
Correct |
16 ms |
23936 KB |
Output is correct |
24 |
Correct |
16 ms |
24044 KB |
Output is correct |
25 |
Correct |
19 ms |
23916 KB |
Output is correct |
26 |
Correct |
19 ms |
23916 KB |
Output is correct |
27 |
Correct |
16 ms |
23916 KB |
Output is correct |
28 |
Correct |
19 ms |
23916 KB |
Output is correct |
29 |
Correct |
17 ms |
23884 KB |
Output is correct |
30 |
Correct |
18 ms |
23916 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
23788 KB |
Output is correct |
2 |
Correct |
16 ms |
23788 KB |
Output is correct |
3 |
Correct |
16 ms |
23788 KB |
Output is correct |
4 |
Correct |
16 ms |
23788 KB |
Output is correct |
5 |
Correct |
16 ms |
23788 KB |
Output is correct |
6 |
Correct |
16 ms |
23788 KB |
Output is correct |
7 |
Correct |
16 ms |
23916 KB |
Output is correct |
8 |
Correct |
16 ms |
23788 KB |
Output is correct |
9 |
Correct |
16 ms |
23788 KB |
Output is correct |
10 |
Correct |
16 ms |
23788 KB |
Output is correct |
11 |
Correct |
16 ms |
23780 KB |
Output is correct |
12 |
Correct |
16 ms |
23788 KB |
Output is correct |
13 |
Correct |
17 ms |
23788 KB |
Output is correct |
14 |
Correct |
16 ms |
23788 KB |
Output is correct |
15 |
Correct |
16 ms |
23788 KB |
Output is correct |
16 |
Correct |
16 ms |
23788 KB |
Output is correct |
17 |
Correct |
16 ms |
23916 KB |
Output is correct |
18 |
Correct |
17 ms |
23916 KB |
Output is correct |
19 |
Correct |
18 ms |
23916 KB |
Output is correct |
20 |
Correct |
16 ms |
23916 KB |
Output is correct |
21 |
Correct |
16 ms |
23916 KB |
Output is correct |
22 |
Correct |
16 ms |
23916 KB |
Output is correct |
23 |
Correct |
16 ms |
23936 KB |
Output is correct |
24 |
Correct |
16 ms |
24044 KB |
Output is correct |
25 |
Correct |
19 ms |
23916 KB |
Output is correct |
26 |
Correct |
19 ms |
23916 KB |
Output is correct |
27 |
Correct |
16 ms |
23916 KB |
Output is correct |
28 |
Correct |
19 ms |
23916 KB |
Output is correct |
29 |
Correct |
17 ms |
23884 KB |
Output is correct |
30 |
Correct |
18 ms |
23916 KB |
Output is correct |
31 |
Correct |
17 ms |
24044 KB |
Output is correct |
32 |
Correct |
18 ms |
24172 KB |
Output is correct |
33 |
Correct |
18 ms |
24172 KB |
Output is correct |
34 |
Correct |
21 ms |
24192 KB |
Output is correct |
35 |
Correct |
19 ms |
24172 KB |
Output is correct |
36 |
Correct |
20 ms |
24300 KB |
Output is correct |
37 |
Correct |
18 ms |
24044 KB |
Output is correct |
38 |
Correct |
17 ms |
24044 KB |
Output is correct |
39 |
Correct |
18 ms |
24172 KB |
Output is correct |
40 |
Correct |
18 ms |
24172 KB |
Output is correct |
41 |
Correct |
17 ms |
24172 KB |
Output is correct |
42 |
Correct |
20 ms |
24172 KB |
Output is correct |
43 |
Correct |
17 ms |
24172 KB |
Output is correct |
44 |
Correct |
18 ms |
24172 KB |
Output is correct |
45 |
Correct |
17 ms |
24172 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
23788 KB |
Output is correct |
2 |
Correct |
16 ms |
23788 KB |
Output is correct |
3 |
Correct |
16 ms |
23788 KB |
Output is correct |
4 |
Correct |
16 ms |
23788 KB |
Output is correct |
5 |
Correct |
16 ms |
23788 KB |
Output is correct |
6 |
Correct |
16 ms |
23788 KB |
Output is correct |
7 |
Correct |
16 ms |
23916 KB |
Output is correct |
8 |
Correct |
16 ms |
23788 KB |
Output is correct |
9 |
Correct |
16 ms |
23788 KB |
Output is correct |
10 |
Correct |
16 ms |
23788 KB |
Output is correct |
11 |
Correct |
16 ms |
23780 KB |
Output is correct |
12 |
Correct |
16 ms |
23788 KB |
Output is correct |
13 |
Correct |
17 ms |
23788 KB |
Output is correct |
14 |
Correct |
16 ms |
23788 KB |
Output is correct |
15 |
Correct |
16 ms |
23788 KB |
Output is correct |
16 |
Correct |
16 ms |
23788 KB |
Output is correct |
17 |
Correct |
16 ms |
23916 KB |
Output is correct |
18 |
Correct |
17 ms |
23916 KB |
Output is correct |
19 |
Correct |
18 ms |
23916 KB |
Output is correct |
20 |
Correct |
16 ms |
23916 KB |
Output is correct |
21 |
Correct |
16 ms |
23916 KB |
Output is correct |
22 |
Correct |
16 ms |
23916 KB |
Output is correct |
23 |
Correct |
16 ms |
23936 KB |
Output is correct |
24 |
Correct |
16 ms |
24044 KB |
Output is correct |
25 |
Correct |
19 ms |
23916 KB |
Output is correct |
26 |
Correct |
19 ms |
23916 KB |
Output is correct |
27 |
Correct |
16 ms |
23916 KB |
Output is correct |
28 |
Correct |
19 ms |
23916 KB |
Output is correct |
29 |
Correct |
17 ms |
23884 KB |
Output is correct |
30 |
Correct |
18 ms |
23916 KB |
Output is correct |
31 |
Correct |
17 ms |
24044 KB |
Output is correct |
32 |
Correct |
18 ms |
24172 KB |
Output is correct |
33 |
Correct |
18 ms |
24172 KB |
Output is correct |
34 |
Correct |
21 ms |
24192 KB |
Output is correct |
35 |
Correct |
19 ms |
24172 KB |
Output is correct |
36 |
Correct |
20 ms |
24300 KB |
Output is correct |
37 |
Correct |
18 ms |
24044 KB |
Output is correct |
38 |
Correct |
17 ms |
24044 KB |
Output is correct |
39 |
Correct |
18 ms |
24172 KB |
Output is correct |
40 |
Correct |
18 ms |
24172 KB |
Output is correct |
41 |
Correct |
17 ms |
24172 KB |
Output is correct |
42 |
Correct |
20 ms |
24172 KB |
Output is correct |
43 |
Correct |
17 ms |
24172 KB |
Output is correct |
44 |
Correct |
18 ms |
24172 KB |
Output is correct |
45 |
Correct |
17 ms |
24172 KB |
Output is correct |
46 |
Correct |
35 ms |
29292 KB |
Output is correct |
47 |
Correct |
59 ms |
33772 KB |
Output is correct |
48 |
Correct |
72 ms |
34028 KB |
Output is correct |
49 |
Correct |
69 ms |
34028 KB |
Output is correct |
50 |
Correct |
65 ms |
34028 KB |
Output is correct |
51 |
Correct |
62 ms |
34028 KB |
Output is correct |
52 |
Correct |
40 ms |
28908 KB |
Output is correct |
53 |
Correct |
30 ms |
26860 KB |
Output is correct |
54 |
Correct |
58 ms |
34028 KB |
Output is correct |
55 |
Correct |
63 ms |
34028 KB |
Output is correct |
56 |
Correct |
64 ms |
34028 KB |
Output is correct |
57 |
Correct |
58 ms |
34028 KB |
Output is correct |
58 |
Correct |
60 ms |
34028 KB |
Output is correct |
59 |
Correct |
65 ms |
34060 KB |
Output is correct |
60 |
Correct |
62 ms |
34028 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
23788 KB |
Output is correct |
2 |
Correct |
16 ms |
23788 KB |
Output is correct |
3 |
Correct |
16 ms |
23788 KB |
Output is correct |
4 |
Correct |
16 ms |
23788 KB |
Output is correct |
5 |
Correct |
16 ms |
23788 KB |
Output is correct |
6 |
Correct |
16 ms |
23788 KB |
Output is correct |
7 |
Correct |
16 ms |
23916 KB |
Output is correct |
8 |
Correct |
16 ms |
23788 KB |
Output is correct |
9 |
Correct |
16 ms |
23788 KB |
Output is correct |
10 |
Correct |
16 ms |
23788 KB |
Output is correct |
11 |
Correct |
16 ms |
23780 KB |
Output is correct |
12 |
Correct |
16 ms |
23788 KB |
Output is correct |
13 |
Correct |
17 ms |
23788 KB |
Output is correct |
14 |
Correct |
16 ms |
23788 KB |
Output is correct |
15 |
Correct |
16 ms |
23788 KB |
Output is correct |
16 |
Correct |
16 ms |
23788 KB |
Output is correct |
17 |
Correct |
16 ms |
23916 KB |
Output is correct |
18 |
Correct |
17 ms |
23916 KB |
Output is correct |
19 |
Correct |
18 ms |
23916 KB |
Output is correct |
20 |
Correct |
16 ms |
23916 KB |
Output is correct |
21 |
Correct |
16 ms |
23916 KB |
Output is correct |
22 |
Correct |
16 ms |
23916 KB |
Output is correct |
23 |
Correct |
16 ms |
23936 KB |
Output is correct |
24 |
Correct |
16 ms |
24044 KB |
Output is correct |
25 |
Correct |
19 ms |
23916 KB |
Output is correct |
26 |
Correct |
19 ms |
23916 KB |
Output is correct |
27 |
Correct |
16 ms |
23916 KB |
Output is correct |
28 |
Correct |
19 ms |
23916 KB |
Output is correct |
29 |
Correct |
17 ms |
23884 KB |
Output is correct |
30 |
Correct |
18 ms |
23916 KB |
Output is correct |
31 |
Correct |
17 ms |
24044 KB |
Output is correct |
32 |
Correct |
18 ms |
24172 KB |
Output is correct |
33 |
Correct |
18 ms |
24172 KB |
Output is correct |
34 |
Correct |
21 ms |
24192 KB |
Output is correct |
35 |
Correct |
19 ms |
24172 KB |
Output is correct |
36 |
Correct |
20 ms |
24300 KB |
Output is correct |
37 |
Correct |
18 ms |
24044 KB |
Output is correct |
38 |
Correct |
17 ms |
24044 KB |
Output is correct |
39 |
Correct |
18 ms |
24172 KB |
Output is correct |
40 |
Correct |
18 ms |
24172 KB |
Output is correct |
41 |
Correct |
17 ms |
24172 KB |
Output is correct |
42 |
Correct |
20 ms |
24172 KB |
Output is correct |
43 |
Correct |
17 ms |
24172 KB |
Output is correct |
44 |
Correct |
18 ms |
24172 KB |
Output is correct |
45 |
Correct |
17 ms |
24172 KB |
Output is correct |
46 |
Correct |
35 ms |
29292 KB |
Output is correct |
47 |
Correct |
59 ms |
33772 KB |
Output is correct |
48 |
Correct |
72 ms |
34028 KB |
Output is correct |
49 |
Correct |
69 ms |
34028 KB |
Output is correct |
50 |
Correct |
65 ms |
34028 KB |
Output is correct |
51 |
Correct |
62 ms |
34028 KB |
Output is correct |
52 |
Correct |
40 ms |
28908 KB |
Output is correct |
53 |
Correct |
30 ms |
26860 KB |
Output is correct |
54 |
Correct |
58 ms |
34028 KB |
Output is correct |
55 |
Correct |
63 ms |
34028 KB |
Output is correct |
56 |
Correct |
64 ms |
34028 KB |
Output is correct |
57 |
Correct |
58 ms |
34028 KB |
Output is correct |
58 |
Correct |
60 ms |
34028 KB |
Output is correct |
59 |
Correct |
65 ms |
34060 KB |
Output is correct |
60 |
Correct |
62 ms |
34028 KB |
Output is correct |
61 |
Correct |
113 ms |
51180 KB |
Output is correct |
62 |
Correct |
153 ms |
62960 KB |
Output is correct |
63 |
Correct |
236 ms |
72412 KB |
Output is correct |
64 |
Correct |
298 ms |
74692 KB |
Output is correct |
65 |
Correct |
270 ms |
74732 KB |
Output is correct |
66 |
Correct |
254 ms |
74732 KB |
Output is correct |
67 |
Correct |
210 ms |
64520 KB |
Output is correct |
68 |
Correct |
109 ms |
44140 KB |
Output is correct |
69 |
Correct |
229 ms |
74732 KB |
Output is correct |
70 |
Correct |
245 ms |
74732 KB |
Output is correct |
71 |
Correct |
250 ms |
74732 KB |
Output is correct |
72 |
Correct |
235 ms |
74732 KB |
Output is correct |
73 |
Correct |
257 ms |
74732 KB |
Output is correct |
74 |
Correct |
265 ms |
74732 KB |
Output is correct |
75 |
Correct |
254 ms |
74732 KB |
Output is correct |