#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long oo = 1LL * 1e15;
const int N = 5e5;
int n;
struct ST{
vector<long long> t;
void uni(){
t.resize(N * 3);
for(auto &i:t)i = -oo;
}
void upd(int poz, ll val, int v = 1, int l = 0, int r = n - 1){
if(poz < 0)return;
if(l == r){t[v] = val;return;}
int c = (l + r)>>1;
if(poz <= c)upd(poz, val, v<<1, l, c);
else upd(poz, val, (v<<1)|1, c+1, r);
t[v] = max(t[v<<1], t[(v<<1)|1]);
}
int get(long long val, int v = 1, int l = 0, int r = n - 1){
if(l == r)return l;
int c = (l + r) >> 1;
if(t[(v<<1)|1]>=val)return get(val, (v<<1)|1,c+1,r);
return get(val, v<<1,l,c);
}
};
int32_t main() {
ios_base::sync_with_stdio(0);
//cout<<oo<<endl;
cin>>n;
int a[n];
for(int i = 0; i < n; i += 1)cin>>a[i];
ll sf[n + 1] = {};
for(int i = n - 1; i >= 0; i -= 1)sf[i] = sf[i + 1] + a[i];
///dp[p] = {ans, min_sum}
pair<int,ll> dp[n];
ll sum = 0;
for(int i = 0; i < n; i += 1){
sum += a[i];
dp[i] = {1, sum};
}
ST tree;
tree.uni();
tree.upd(0, sf[1] - dp[0].second);
//cerr<<"upd: "<<sf[1] - dp[0].second<<endl;
for(int i = 1; i < n; i += 1){
int poz = tree.get(sf[i + 1]);
//cerr<<"poz = "<<poz<<" get: "<<sf[i + 1]<<endl;
if(tree.t[1] >= sf[i + 1]){
dp[i] = max(dp[i], {dp[poz].first + 1, sf[poz + 1] - sf[i + 1]});
//cerr<<"upd: "<<sf[i + 1] - dp[i].second<<endl;
}
tree.upd(i, sf[i + 1] - dp[i].second);
}
// cout<<"dp:";
// for(int i = 0; i < n; i += 1)cout<<dp[i].first<<' '<<dp[i].second<<endl;
int ans = 0;
for(int i = 0; i < n; i += 1){
ans = max(ans, dp[i].first);
}
cout<<ans;
}
/*
5
6 2 3 9 13
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
12120 KB |
Output is correct |
2 |
Correct |
3 ms |
12120 KB |
Output is correct |
3 |
Correct |
3 ms |
12120 KB |
Output is correct |
4 |
Correct |
3 ms |
12120 KB |
Output is correct |
5 |
Correct |
3 ms |
12120 KB |
Output is correct |
6 |
Correct |
3 ms |
12120 KB |
Output is correct |
7 |
Correct |
3 ms |
12120 KB |
Output is correct |
8 |
Correct |
3 ms |
12120 KB |
Output is correct |
9 |
Correct |
3 ms |
12120 KB |
Output is correct |
10 |
Correct |
2 ms |
12124 KB |
Output is correct |
11 |
Correct |
2 ms |
12124 KB |
Output is correct |
12 |
Correct |
2 ms |
12120 KB |
Output is correct |
13 |
Correct |
3 ms |
12120 KB |
Output is correct |
14 |
Correct |
2 ms |
12124 KB |
Output is correct |
15 |
Correct |
4 ms |
12376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
12120 KB |
Output is correct |
2 |
Correct |
3 ms |
12120 KB |
Output is correct |
3 |
Correct |
3 ms |
12120 KB |
Output is correct |
4 |
Correct |
3 ms |
12120 KB |
Output is correct |
5 |
Correct |
3 ms |
12120 KB |
Output is correct |
6 |
Correct |
3 ms |
12120 KB |
Output is correct |
7 |
Correct |
3 ms |
12120 KB |
Output is correct |
8 |
Correct |
3 ms |
12120 KB |
Output is correct |
9 |
Correct |
3 ms |
12120 KB |
Output is correct |
10 |
Correct |
2 ms |
12124 KB |
Output is correct |
11 |
Correct |
2 ms |
12124 KB |
Output is correct |
12 |
Correct |
2 ms |
12120 KB |
Output is correct |
13 |
Correct |
3 ms |
12120 KB |
Output is correct |
14 |
Correct |
2 ms |
12124 KB |
Output is correct |
15 |
Correct |
4 ms |
12376 KB |
Output is correct |
16 |
Correct |
3 ms |
12120 KB |
Output is correct |
17 |
Correct |
3 ms |
12120 KB |
Output is correct |
18 |
Correct |
3 ms |
12120 KB |
Output is correct |
19 |
Correct |
2 ms |
12124 KB |
Output is correct |
20 |
Correct |
3 ms |
12120 KB |
Output is correct |
21 |
Correct |
2 ms |
12120 KB |
Output is correct |
22 |
Correct |
3 ms |
12120 KB |
Output is correct |
23 |
Correct |
3 ms |
12120 KB |
Output is correct |
24 |
Correct |
3 ms |
12120 KB |
Output is correct |
25 |
Correct |
3 ms |
12120 KB |
Output is correct |
26 |
Correct |
3 ms |
12120 KB |
Output is correct |
27 |
Correct |
2 ms |
12132 KB |
Output is correct |
28 |
Correct |
3 ms |
12120 KB |
Output is correct |
29 |
Correct |
3 ms |
12124 KB |
Output is correct |
30 |
Correct |
2 ms |
12124 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
12120 KB |
Output is correct |
2 |
Correct |
3 ms |
12120 KB |
Output is correct |
3 |
Correct |
3 ms |
12120 KB |
Output is correct |
4 |
Correct |
3 ms |
12120 KB |
Output is correct |
5 |
Correct |
3 ms |
12120 KB |
Output is correct |
6 |
Correct |
3 ms |
12120 KB |
Output is correct |
7 |
Correct |
3 ms |
12120 KB |
Output is correct |
8 |
Correct |
3 ms |
12120 KB |
Output is correct |
9 |
Correct |
3 ms |
12120 KB |
Output is correct |
10 |
Correct |
2 ms |
12124 KB |
Output is correct |
11 |
Correct |
2 ms |
12124 KB |
Output is correct |
12 |
Correct |
2 ms |
12120 KB |
Output is correct |
13 |
Correct |
3 ms |
12120 KB |
Output is correct |
14 |
Correct |
2 ms |
12124 KB |
Output is correct |
15 |
Correct |
4 ms |
12376 KB |
Output is correct |
16 |
Correct |
3 ms |
12120 KB |
Output is correct |
17 |
Correct |
3 ms |
12120 KB |
Output is correct |
18 |
Correct |
3 ms |
12120 KB |
Output is correct |
19 |
Correct |
2 ms |
12124 KB |
Output is correct |
20 |
Correct |
3 ms |
12120 KB |
Output is correct |
21 |
Correct |
2 ms |
12120 KB |
Output is correct |
22 |
Correct |
3 ms |
12120 KB |
Output is correct |
23 |
Correct |
3 ms |
12120 KB |
Output is correct |
24 |
Correct |
3 ms |
12120 KB |
Output is correct |
25 |
Correct |
3 ms |
12120 KB |
Output is correct |
26 |
Correct |
3 ms |
12120 KB |
Output is correct |
27 |
Correct |
2 ms |
12132 KB |
Output is correct |
28 |
Correct |
3 ms |
12120 KB |
Output is correct |
29 |
Correct |
3 ms |
12124 KB |
Output is correct |
30 |
Correct |
2 ms |
12124 KB |
Output is correct |
31 |
Correct |
4 ms |
12120 KB |
Output is correct |
32 |
Correct |
3 ms |
12120 KB |
Output is correct |
33 |
Correct |
3 ms |
12120 KB |
Output is correct |
34 |
Correct |
3 ms |
12376 KB |
Output is correct |
35 |
Correct |
3 ms |
12120 KB |
Output is correct |
36 |
Correct |
3 ms |
12120 KB |
Output is correct |
37 |
Correct |
3 ms |
12124 KB |
Output is correct |
38 |
Correct |
3 ms |
12120 KB |
Output is correct |
39 |
Correct |
4 ms |
12120 KB |
Output is correct |
40 |
Correct |
4 ms |
12120 KB |
Output is correct |
41 |
Correct |
4 ms |
12124 KB |
Output is correct |
42 |
Correct |
4 ms |
12120 KB |
Output is correct |
43 |
Correct |
4 ms |
12120 KB |
Output is correct |
44 |
Correct |
3 ms |
12120 KB |
Output is correct |
45 |
Correct |
3 ms |
12376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
12120 KB |
Output is correct |
2 |
Correct |
3 ms |
12120 KB |
Output is correct |
3 |
Correct |
3 ms |
12120 KB |
Output is correct |
4 |
Correct |
3 ms |
12120 KB |
Output is correct |
5 |
Correct |
3 ms |
12120 KB |
Output is correct |
6 |
Correct |
3 ms |
12120 KB |
Output is correct |
7 |
Correct |
3 ms |
12120 KB |
Output is correct |
8 |
Correct |
3 ms |
12120 KB |
Output is correct |
9 |
Correct |
3 ms |
12120 KB |
Output is correct |
10 |
Correct |
2 ms |
12124 KB |
Output is correct |
11 |
Correct |
2 ms |
12124 KB |
Output is correct |
12 |
Correct |
2 ms |
12120 KB |
Output is correct |
13 |
Correct |
3 ms |
12120 KB |
Output is correct |
14 |
Correct |
2 ms |
12124 KB |
Output is correct |
15 |
Correct |
4 ms |
12376 KB |
Output is correct |
16 |
Correct |
3 ms |
12120 KB |
Output is correct |
17 |
Correct |
3 ms |
12120 KB |
Output is correct |
18 |
Correct |
3 ms |
12120 KB |
Output is correct |
19 |
Correct |
2 ms |
12124 KB |
Output is correct |
20 |
Correct |
3 ms |
12120 KB |
Output is correct |
21 |
Correct |
2 ms |
12120 KB |
Output is correct |
22 |
Correct |
3 ms |
12120 KB |
Output is correct |
23 |
Correct |
3 ms |
12120 KB |
Output is correct |
24 |
Correct |
3 ms |
12120 KB |
Output is correct |
25 |
Correct |
3 ms |
12120 KB |
Output is correct |
26 |
Correct |
3 ms |
12120 KB |
Output is correct |
27 |
Correct |
2 ms |
12132 KB |
Output is correct |
28 |
Correct |
3 ms |
12120 KB |
Output is correct |
29 |
Correct |
3 ms |
12124 KB |
Output is correct |
30 |
Correct |
2 ms |
12124 KB |
Output is correct |
31 |
Correct |
4 ms |
12120 KB |
Output is correct |
32 |
Correct |
3 ms |
12120 KB |
Output is correct |
33 |
Correct |
3 ms |
12120 KB |
Output is correct |
34 |
Correct |
3 ms |
12376 KB |
Output is correct |
35 |
Correct |
3 ms |
12120 KB |
Output is correct |
36 |
Correct |
3 ms |
12120 KB |
Output is correct |
37 |
Correct |
3 ms |
12124 KB |
Output is correct |
38 |
Correct |
3 ms |
12120 KB |
Output is correct |
39 |
Correct |
4 ms |
12120 KB |
Output is correct |
40 |
Correct |
4 ms |
12120 KB |
Output is correct |
41 |
Correct |
4 ms |
12124 KB |
Output is correct |
42 |
Correct |
4 ms |
12120 KB |
Output is correct |
43 |
Correct |
4 ms |
12120 KB |
Output is correct |
44 |
Correct |
3 ms |
12120 KB |
Output is correct |
45 |
Correct |
3 ms |
12376 KB |
Output is correct |
46 |
Correct |
17 ms |
14936 KB |
Output is correct |
47 |
Correct |
19 ms |
14936 KB |
Output is correct |
48 |
Correct |
22 ms |
15720 KB |
Output is correct |
49 |
Correct |
25 ms |
15696 KB |
Output is correct |
50 |
Correct |
23 ms |
15704 KB |
Output is correct |
51 |
Correct |
25 ms |
15704 KB |
Output is correct |
52 |
Correct |
13 ms |
13912 KB |
Output is correct |
53 |
Correct |
8 ms |
13144 KB |
Output is correct |
54 |
Correct |
19 ms |
14936 KB |
Output is correct |
55 |
Correct |
23 ms |
15700 KB |
Output is correct |
56 |
Correct |
22 ms |
15192 KB |
Output is correct |
57 |
Correct |
20 ms |
15192 KB |
Output is correct |
58 |
Correct |
20 ms |
15192 KB |
Output is correct |
59 |
Correct |
23 ms |
15704 KB |
Output is correct |
60 |
Correct |
21 ms |
15448 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
12120 KB |
Output is correct |
2 |
Correct |
3 ms |
12120 KB |
Output is correct |
3 |
Correct |
3 ms |
12120 KB |
Output is correct |
4 |
Correct |
3 ms |
12120 KB |
Output is correct |
5 |
Correct |
3 ms |
12120 KB |
Output is correct |
6 |
Correct |
3 ms |
12120 KB |
Output is correct |
7 |
Correct |
3 ms |
12120 KB |
Output is correct |
8 |
Correct |
3 ms |
12120 KB |
Output is correct |
9 |
Correct |
3 ms |
12120 KB |
Output is correct |
10 |
Correct |
2 ms |
12124 KB |
Output is correct |
11 |
Correct |
2 ms |
12124 KB |
Output is correct |
12 |
Correct |
2 ms |
12120 KB |
Output is correct |
13 |
Correct |
3 ms |
12120 KB |
Output is correct |
14 |
Correct |
2 ms |
12124 KB |
Output is correct |
15 |
Correct |
4 ms |
12376 KB |
Output is correct |
16 |
Correct |
3 ms |
12120 KB |
Output is correct |
17 |
Correct |
3 ms |
12120 KB |
Output is correct |
18 |
Correct |
3 ms |
12120 KB |
Output is correct |
19 |
Correct |
2 ms |
12124 KB |
Output is correct |
20 |
Correct |
3 ms |
12120 KB |
Output is correct |
21 |
Correct |
2 ms |
12120 KB |
Output is correct |
22 |
Correct |
3 ms |
12120 KB |
Output is correct |
23 |
Correct |
3 ms |
12120 KB |
Output is correct |
24 |
Correct |
3 ms |
12120 KB |
Output is correct |
25 |
Correct |
3 ms |
12120 KB |
Output is correct |
26 |
Correct |
3 ms |
12120 KB |
Output is correct |
27 |
Correct |
2 ms |
12132 KB |
Output is correct |
28 |
Correct |
3 ms |
12120 KB |
Output is correct |
29 |
Correct |
3 ms |
12124 KB |
Output is correct |
30 |
Correct |
2 ms |
12124 KB |
Output is correct |
31 |
Correct |
4 ms |
12120 KB |
Output is correct |
32 |
Correct |
3 ms |
12120 KB |
Output is correct |
33 |
Correct |
3 ms |
12120 KB |
Output is correct |
34 |
Correct |
3 ms |
12376 KB |
Output is correct |
35 |
Correct |
3 ms |
12120 KB |
Output is correct |
36 |
Correct |
3 ms |
12120 KB |
Output is correct |
37 |
Correct |
3 ms |
12124 KB |
Output is correct |
38 |
Correct |
3 ms |
12120 KB |
Output is correct |
39 |
Correct |
4 ms |
12120 KB |
Output is correct |
40 |
Correct |
4 ms |
12120 KB |
Output is correct |
41 |
Correct |
4 ms |
12124 KB |
Output is correct |
42 |
Correct |
4 ms |
12120 KB |
Output is correct |
43 |
Correct |
4 ms |
12120 KB |
Output is correct |
44 |
Correct |
3 ms |
12120 KB |
Output is correct |
45 |
Correct |
3 ms |
12376 KB |
Output is correct |
46 |
Correct |
17 ms |
14936 KB |
Output is correct |
47 |
Correct |
19 ms |
14936 KB |
Output is correct |
48 |
Correct |
22 ms |
15720 KB |
Output is correct |
49 |
Correct |
25 ms |
15696 KB |
Output is correct |
50 |
Correct |
23 ms |
15704 KB |
Output is correct |
51 |
Correct |
25 ms |
15704 KB |
Output is correct |
52 |
Correct |
13 ms |
13912 KB |
Output is correct |
53 |
Correct |
8 ms |
13144 KB |
Output is correct |
54 |
Correct |
19 ms |
14936 KB |
Output is correct |
55 |
Correct |
23 ms |
15700 KB |
Output is correct |
56 |
Correct |
22 ms |
15192 KB |
Output is correct |
57 |
Correct |
20 ms |
15192 KB |
Output is correct |
58 |
Correct |
20 ms |
15192 KB |
Output is correct |
59 |
Correct |
23 ms |
15704 KB |
Output is correct |
60 |
Correct |
21 ms |
15448 KB |
Output is correct |
61 |
Correct |
83 ms |
27728 KB |
Output is correct |
62 |
Correct |
96 ms |
27728 KB |
Output is correct |
63 |
Correct |
96 ms |
27984 KB |
Output is correct |
64 |
Correct |
109 ms |
30288 KB |
Output is correct |
65 |
Correct |
118 ms |
30544 KB |
Output is correct |
66 |
Correct |
110 ms |
30548 KB |
Output is correct |
67 |
Correct |
88 ms |
26960 KB |
Output is correct |
68 |
Correct |
44 ms |
19540 KB |
Output is correct |
69 |
Correct |
97 ms |
26744 KB |
Output is correct |
70 |
Correct |
110 ms |
30656 KB |
Output is correct |
71 |
Correct |
96 ms |
27728 KB |
Output is correct |
72 |
Correct |
96 ms |
27984 KB |
Output is correct |
73 |
Correct |
99 ms |
28752 KB |
Output is correct |
74 |
Correct |
102 ms |
29004 KB |
Output is correct |
75 |
Correct |
102 ms |
29008 KB |
Output is correct |