#include <bits/stdc++.h>
using namespace std;
#define pii pair<ll,ll>
#define REP(i,x,y) for(ll i=x;i<=y;i++)
#define freeopen freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
#define mod 1000000000
#define pb push_back
#define mk make_pair
#define ll long long
#define foor(x,vec) for(auto x:vec ){cout<<x<<" ";}
#define fi first
#define se second
#define MAXN 500069
#define lld long double
#define cha ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ffl fflush(stdout)
#define sst string
#define pii pair<ll,ll>
ll mvx[]={0,0,-1,1};
ll mvy[]={1,-1,0,0};
ll n;
ll a[MAXN],b[MAXN],ps[MAXN],dp[MAXN];
ll pos[MAXN],pos2[MAXN];
vector <ll> adj[MAXN];
map<ll,ll> mp;
void solve(){
cin>>n;
REP(i,1,n){
cin>>a[i];
}
REP(i,1,n){
ps[i]=ps[i-1]+a[i];
}
dp[1]=1;
REP(i,1,n){
pos[i]=max(pos[i-1],pos[i]);
dp[i]=dp[pos[i]]+1;
ll lb=lower_bound(ps+1,ps+n+1,ps[i]+ps[i]-ps[pos[i]])-ps;
pos[lb]=i;
}
/*
1 1 1 2 3
0 0 0 2 4
6 8 10 18 29
ps[i]-ps[pos[i]>=ps[j]]-ps[i]
ps[j]>=ps[i]*2-ps[pos[i]]
ps[j]-ps[i]>=ps[i]-ps[pos[i]]
ps[i]+ps[pos[i]]>=ps[j]
*/
cout<<dp[n]<<endl;
}
int main(){
ll tc;
tc=1;
// cin>>tc;
while(tc--){
solve();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
16988 KB |
Output is correct |
2 |
Correct |
2 ms |
16988 KB |
Output is correct |
3 |
Correct |
2 ms |
16988 KB |
Output is correct |
4 |
Correct |
3 ms |
16988 KB |
Output is correct |
5 |
Correct |
2 ms |
17028 KB |
Output is correct |
6 |
Correct |
2 ms |
16988 KB |
Output is correct |
7 |
Correct |
2 ms |
16988 KB |
Output is correct |
8 |
Correct |
2 ms |
16988 KB |
Output is correct |
9 |
Correct |
2 ms |
16984 KB |
Output is correct |
10 |
Correct |
2 ms |
17008 KB |
Output is correct |
11 |
Correct |
3 ms |
16988 KB |
Output is correct |
12 |
Correct |
2 ms |
16988 KB |
Output is correct |
13 |
Correct |
3 ms |
16988 KB |
Output is correct |
14 |
Correct |
3 ms |
16988 KB |
Output is correct |
15 |
Correct |
2 ms |
16988 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
16988 KB |
Output is correct |
2 |
Correct |
2 ms |
16988 KB |
Output is correct |
3 |
Correct |
2 ms |
16988 KB |
Output is correct |
4 |
Correct |
3 ms |
16988 KB |
Output is correct |
5 |
Correct |
2 ms |
17028 KB |
Output is correct |
6 |
Correct |
2 ms |
16988 KB |
Output is correct |
7 |
Correct |
2 ms |
16988 KB |
Output is correct |
8 |
Correct |
2 ms |
16988 KB |
Output is correct |
9 |
Correct |
2 ms |
16984 KB |
Output is correct |
10 |
Correct |
2 ms |
17008 KB |
Output is correct |
11 |
Correct |
3 ms |
16988 KB |
Output is correct |
12 |
Correct |
2 ms |
16988 KB |
Output is correct |
13 |
Correct |
3 ms |
16988 KB |
Output is correct |
14 |
Correct |
3 ms |
16988 KB |
Output is correct |
15 |
Correct |
2 ms |
16988 KB |
Output is correct |
16 |
Correct |
3 ms |
16988 KB |
Output is correct |
17 |
Correct |
2 ms |
16988 KB |
Output is correct |
18 |
Correct |
2 ms |
16988 KB |
Output is correct |
19 |
Correct |
3 ms |
16988 KB |
Output is correct |
20 |
Correct |
3 ms |
16988 KB |
Output is correct |
21 |
Correct |
2 ms |
16988 KB |
Output is correct |
22 |
Correct |
2 ms |
16988 KB |
Output is correct |
23 |
Correct |
2 ms |
16988 KB |
Output is correct |
24 |
Correct |
2 ms |
16988 KB |
Output is correct |
25 |
Correct |
2 ms |
16988 KB |
Output is correct |
26 |
Correct |
2 ms |
16988 KB |
Output is correct |
27 |
Correct |
3 ms |
16988 KB |
Output is correct |
28 |
Correct |
2 ms |
16988 KB |
Output is correct |
29 |
Correct |
2 ms |
16988 KB |
Output is correct |
30 |
Correct |
2 ms |
16988 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
16988 KB |
Output is correct |
2 |
Correct |
2 ms |
16988 KB |
Output is correct |
3 |
Correct |
2 ms |
16988 KB |
Output is correct |
4 |
Correct |
3 ms |
16988 KB |
Output is correct |
5 |
Correct |
2 ms |
17028 KB |
Output is correct |
6 |
Correct |
2 ms |
16988 KB |
Output is correct |
7 |
Correct |
2 ms |
16988 KB |
Output is correct |
8 |
Correct |
2 ms |
16988 KB |
Output is correct |
9 |
Correct |
2 ms |
16984 KB |
Output is correct |
10 |
Correct |
2 ms |
17008 KB |
Output is correct |
11 |
Correct |
3 ms |
16988 KB |
Output is correct |
12 |
Correct |
2 ms |
16988 KB |
Output is correct |
13 |
Correct |
3 ms |
16988 KB |
Output is correct |
14 |
Correct |
3 ms |
16988 KB |
Output is correct |
15 |
Correct |
2 ms |
16988 KB |
Output is correct |
16 |
Correct |
3 ms |
16988 KB |
Output is correct |
17 |
Correct |
2 ms |
16988 KB |
Output is correct |
18 |
Correct |
2 ms |
16988 KB |
Output is correct |
19 |
Correct |
3 ms |
16988 KB |
Output is correct |
20 |
Correct |
3 ms |
16988 KB |
Output is correct |
21 |
Correct |
2 ms |
16988 KB |
Output is correct |
22 |
Correct |
2 ms |
16988 KB |
Output is correct |
23 |
Correct |
2 ms |
16988 KB |
Output is correct |
24 |
Correct |
2 ms |
16988 KB |
Output is correct |
25 |
Correct |
2 ms |
16988 KB |
Output is correct |
26 |
Correct |
2 ms |
16988 KB |
Output is correct |
27 |
Correct |
3 ms |
16988 KB |
Output is correct |
28 |
Correct |
2 ms |
16988 KB |
Output is correct |
29 |
Correct |
2 ms |
16988 KB |
Output is correct |
30 |
Correct |
2 ms |
16988 KB |
Output is correct |
31 |
Correct |
3 ms |
16984 KB |
Output is correct |
32 |
Correct |
3 ms |
16988 KB |
Output is correct |
33 |
Correct |
3 ms |
16988 KB |
Output is correct |
34 |
Correct |
3 ms |
17032 KB |
Output is correct |
35 |
Correct |
3 ms |
16988 KB |
Output is correct |
36 |
Correct |
3 ms |
16988 KB |
Output is correct |
37 |
Correct |
3 ms |
16988 KB |
Output is correct |
38 |
Correct |
3 ms |
16988 KB |
Output is correct |
39 |
Correct |
3 ms |
17064 KB |
Output is correct |
40 |
Correct |
3 ms |
16988 KB |
Output is correct |
41 |
Correct |
3 ms |
16988 KB |
Output is correct |
42 |
Correct |
3 ms |
17076 KB |
Output is correct |
43 |
Correct |
2 ms |
17000 KB |
Output is correct |
44 |
Correct |
3 ms |
16988 KB |
Output is correct |
45 |
Correct |
3 ms |
16988 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
16988 KB |
Output is correct |
2 |
Correct |
2 ms |
16988 KB |
Output is correct |
3 |
Correct |
2 ms |
16988 KB |
Output is correct |
4 |
Correct |
3 ms |
16988 KB |
Output is correct |
5 |
Correct |
2 ms |
17028 KB |
Output is correct |
6 |
Correct |
2 ms |
16988 KB |
Output is correct |
7 |
Correct |
2 ms |
16988 KB |
Output is correct |
8 |
Correct |
2 ms |
16988 KB |
Output is correct |
9 |
Correct |
2 ms |
16984 KB |
Output is correct |
10 |
Correct |
2 ms |
17008 KB |
Output is correct |
11 |
Correct |
3 ms |
16988 KB |
Output is correct |
12 |
Correct |
2 ms |
16988 KB |
Output is correct |
13 |
Correct |
3 ms |
16988 KB |
Output is correct |
14 |
Correct |
3 ms |
16988 KB |
Output is correct |
15 |
Correct |
2 ms |
16988 KB |
Output is correct |
16 |
Correct |
3 ms |
16988 KB |
Output is correct |
17 |
Correct |
2 ms |
16988 KB |
Output is correct |
18 |
Correct |
2 ms |
16988 KB |
Output is correct |
19 |
Correct |
3 ms |
16988 KB |
Output is correct |
20 |
Correct |
3 ms |
16988 KB |
Output is correct |
21 |
Correct |
2 ms |
16988 KB |
Output is correct |
22 |
Correct |
2 ms |
16988 KB |
Output is correct |
23 |
Correct |
2 ms |
16988 KB |
Output is correct |
24 |
Correct |
2 ms |
16988 KB |
Output is correct |
25 |
Correct |
2 ms |
16988 KB |
Output is correct |
26 |
Correct |
2 ms |
16988 KB |
Output is correct |
27 |
Correct |
3 ms |
16988 KB |
Output is correct |
28 |
Correct |
2 ms |
16988 KB |
Output is correct |
29 |
Correct |
2 ms |
16988 KB |
Output is correct |
30 |
Correct |
2 ms |
16988 KB |
Output is correct |
31 |
Correct |
3 ms |
16984 KB |
Output is correct |
32 |
Correct |
3 ms |
16988 KB |
Output is correct |
33 |
Correct |
3 ms |
16988 KB |
Output is correct |
34 |
Correct |
3 ms |
17032 KB |
Output is correct |
35 |
Correct |
3 ms |
16988 KB |
Output is correct |
36 |
Correct |
3 ms |
16988 KB |
Output is correct |
37 |
Correct |
3 ms |
16988 KB |
Output is correct |
38 |
Correct |
3 ms |
16988 KB |
Output is correct |
39 |
Correct |
3 ms |
17064 KB |
Output is correct |
40 |
Correct |
3 ms |
16988 KB |
Output is correct |
41 |
Correct |
3 ms |
16988 KB |
Output is correct |
42 |
Correct |
3 ms |
17076 KB |
Output is correct |
43 |
Correct |
2 ms |
17000 KB |
Output is correct |
44 |
Correct |
3 ms |
16988 KB |
Output is correct |
45 |
Correct |
3 ms |
16988 KB |
Output is correct |
46 |
Correct |
16 ms |
18576 KB |
Output is correct |
47 |
Correct |
18 ms |
18568 KB |
Output is correct |
48 |
Correct |
25 ms |
18572 KB |
Output is correct |
49 |
Correct |
29 ms |
18512 KB |
Output is correct |
50 |
Correct |
29 ms |
18556 KB |
Output is correct |
51 |
Correct |
29 ms |
18512 KB |
Output is correct |
52 |
Correct |
16 ms |
17808 KB |
Output is correct |
53 |
Correct |
10 ms |
17292 KB |
Output is correct |
54 |
Correct |
14 ms |
18520 KB |
Output is correct |
55 |
Correct |
30 ms |
18512 KB |
Output is correct |
56 |
Correct |
19 ms |
18524 KB |
Output is correct |
57 |
Correct |
17 ms |
18524 KB |
Output is correct |
58 |
Correct |
18 ms |
18520 KB |
Output is correct |
59 |
Correct |
21 ms |
18560 KB |
Output is correct |
60 |
Correct |
22 ms |
18520 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
16988 KB |
Output is correct |
2 |
Correct |
2 ms |
16988 KB |
Output is correct |
3 |
Correct |
2 ms |
16988 KB |
Output is correct |
4 |
Correct |
3 ms |
16988 KB |
Output is correct |
5 |
Correct |
2 ms |
17028 KB |
Output is correct |
6 |
Correct |
2 ms |
16988 KB |
Output is correct |
7 |
Correct |
2 ms |
16988 KB |
Output is correct |
8 |
Correct |
2 ms |
16988 KB |
Output is correct |
9 |
Correct |
2 ms |
16984 KB |
Output is correct |
10 |
Correct |
2 ms |
17008 KB |
Output is correct |
11 |
Correct |
3 ms |
16988 KB |
Output is correct |
12 |
Correct |
2 ms |
16988 KB |
Output is correct |
13 |
Correct |
3 ms |
16988 KB |
Output is correct |
14 |
Correct |
3 ms |
16988 KB |
Output is correct |
15 |
Correct |
2 ms |
16988 KB |
Output is correct |
16 |
Correct |
3 ms |
16988 KB |
Output is correct |
17 |
Correct |
2 ms |
16988 KB |
Output is correct |
18 |
Correct |
2 ms |
16988 KB |
Output is correct |
19 |
Correct |
3 ms |
16988 KB |
Output is correct |
20 |
Correct |
3 ms |
16988 KB |
Output is correct |
21 |
Correct |
2 ms |
16988 KB |
Output is correct |
22 |
Correct |
2 ms |
16988 KB |
Output is correct |
23 |
Correct |
2 ms |
16988 KB |
Output is correct |
24 |
Correct |
2 ms |
16988 KB |
Output is correct |
25 |
Correct |
2 ms |
16988 KB |
Output is correct |
26 |
Correct |
2 ms |
16988 KB |
Output is correct |
27 |
Correct |
3 ms |
16988 KB |
Output is correct |
28 |
Correct |
2 ms |
16988 KB |
Output is correct |
29 |
Correct |
2 ms |
16988 KB |
Output is correct |
30 |
Correct |
2 ms |
16988 KB |
Output is correct |
31 |
Correct |
3 ms |
16984 KB |
Output is correct |
32 |
Correct |
3 ms |
16988 KB |
Output is correct |
33 |
Correct |
3 ms |
16988 KB |
Output is correct |
34 |
Correct |
3 ms |
17032 KB |
Output is correct |
35 |
Correct |
3 ms |
16988 KB |
Output is correct |
36 |
Correct |
3 ms |
16988 KB |
Output is correct |
37 |
Correct |
3 ms |
16988 KB |
Output is correct |
38 |
Correct |
3 ms |
16988 KB |
Output is correct |
39 |
Correct |
3 ms |
17064 KB |
Output is correct |
40 |
Correct |
3 ms |
16988 KB |
Output is correct |
41 |
Correct |
3 ms |
16988 KB |
Output is correct |
42 |
Correct |
3 ms |
17076 KB |
Output is correct |
43 |
Correct |
2 ms |
17000 KB |
Output is correct |
44 |
Correct |
3 ms |
16988 KB |
Output is correct |
45 |
Correct |
3 ms |
16988 KB |
Output is correct |
46 |
Correct |
16 ms |
18576 KB |
Output is correct |
47 |
Correct |
18 ms |
18568 KB |
Output is correct |
48 |
Correct |
25 ms |
18572 KB |
Output is correct |
49 |
Correct |
29 ms |
18512 KB |
Output is correct |
50 |
Correct |
29 ms |
18556 KB |
Output is correct |
51 |
Correct |
29 ms |
18512 KB |
Output is correct |
52 |
Correct |
16 ms |
17808 KB |
Output is correct |
53 |
Correct |
10 ms |
17292 KB |
Output is correct |
54 |
Correct |
14 ms |
18520 KB |
Output is correct |
55 |
Correct |
30 ms |
18512 KB |
Output is correct |
56 |
Correct |
19 ms |
18524 KB |
Output is correct |
57 |
Correct |
17 ms |
18524 KB |
Output is correct |
58 |
Correct |
18 ms |
18520 KB |
Output is correct |
59 |
Correct |
21 ms |
18560 KB |
Output is correct |
60 |
Correct |
22 ms |
18520 KB |
Output is correct |
61 |
Correct |
69 ms |
30292 KB |
Output is correct |
62 |
Correct |
67 ms |
30288 KB |
Output is correct |
63 |
Correct |
80 ms |
30332 KB |
Output is correct |
64 |
Correct |
133 ms |
30292 KB |
Output is correct |
65 |
Correct |
142 ms |
30292 KB |
Output is correct |
66 |
Correct |
133 ms |
30336 KB |
Output is correct |
67 |
Correct |
101 ms |
27472 KB |
Output is correct |
68 |
Correct |
55 ms |
25424 KB |
Output is correct |
69 |
Correct |
63 ms |
30288 KB |
Output is correct |
70 |
Correct |
133 ms |
30288 KB |
Output is correct |
71 |
Correct |
81 ms |
30292 KB |
Output is correct |
72 |
Correct |
79 ms |
30288 KB |
Output is correct |
73 |
Correct |
96 ms |
30288 KB |
Output is correct |
74 |
Correct |
110 ms |
30328 KB |
Output is correct |
75 |
Correct |
104 ms |
30328 KB |
Output is correct |