#include <bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
#define ld long double
#define pll pair<ll,ll>
#define y1 Enkognit
#define fi first
#define se second
#define pld pair<ld,ld>
using namespace std;
const ll MOD=1000000007;
ll l, r, n, m, k, x, y, a[1000001], bst[1000001], pr[1000001];
pll dp[1000001];
ll tt[1000001];
vector <ll> an;
ll binpow(ll h,ll r)
{
ll l=1;
while (r)
{
if (r&1) l*=h,l%=MOD;
h*=h;
h%=MOD;
r/=2;
}
return l;
}
int main()
{
ios::sync_with_stdio(0);
cin >> n;
for (ll i = 1; i <= n; i++) {cin >> a[i];pr[i]=pr[i-1]+a[i];}
ll lr=0;
for (ll i = 1; i <= n; i++)
{
lr=max(lr,bst[i]);
dp[i]=mp(pr[i]-pr[lr],dp[lr].se+1);
if (pr[n]-pr[i]>=dp[i].fi)
{
ll l=i+1, r=n;
while (l<r)
{
ll w=(l+r)/2;
if (pr[w]-pr[i]>=dp[i].fi) r=w; else l=w+1;
}
bst[l]=max(bst[l],i);
}
}
cout << dp[n].se;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
380 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
348 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
380 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
396 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
380 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
348 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
380 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
396 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
420 KB |
Output is correct |
19 |
Correct |
2 ms |
424 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
2 ms |
376 KB |
Output is correct |
24 |
Correct |
2 ms |
376 KB |
Output is correct |
25 |
Correct |
2 ms |
376 KB |
Output is correct |
26 |
Correct |
2 ms |
376 KB |
Output is correct |
27 |
Correct |
2 ms |
376 KB |
Output is correct |
28 |
Correct |
2 ms |
380 KB |
Output is correct |
29 |
Correct |
2 ms |
376 KB |
Output is correct |
30 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
380 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
348 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
380 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
396 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
420 KB |
Output is correct |
19 |
Correct |
2 ms |
424 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
2 ms |
376 KB |
Output is correct |
24 |
Correct |
2 ms |
376 KB |
Output is correct |
25 |
Correct |
2 ms |
376 KB |
Output is correct |
26 |
Correct |
2 ms |
376 KB |
Output is correct |
27 |
Correct |
2 ms |
376 KB |
Output is correct |
28 |
Correct |
2 ms |
380 KB |
Output is correct |
29 |
Correct |
2 ms |
376 KB |
Output is correct |
30 |
Correct |
2 ms |
376 KB |
Output is correct |
31 |
Correct |
2 ms |
504 KB |
Output is correct |
32 |
Correct |
3 ms |
504 KB |
Output is correct |
33 |
Correct |
3 ms |
504 KB |
Output is correct |
34 |
Correct |
2 ms |
504 KB |
Output is correct |
35 |
Correct |
3 ms |
508 KB |
Output is correct |
36 |
Correct |
3 ms |
504 KB |
Output is correct |
37 |
Correct |
3 ms |
508 KB |
Output is correct |
38 |
Correct |
2 ms |
504 KB |
Output is correct |
39 |
Correct |
2 ms |
504 KB |
Output is correct |
40 |
Correct |
3 ms |
504 KB |
Output is correct |
41 |
Correct |
2 ms |
508 KB |
Output is correct |
42 |
Correct |
2 ms |
520 KB |
Output is correct |
43 |
Correct |
3 ms |
508 KB |
Output is correct |
44 |
Correct |
2 ms |
504 KB |
Output is correct |
45 |
Correct |
3 ms |
504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
380 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
348 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
380 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
396 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
420 KB |
Output is correct |
19 |
Correct |
2 ms |
424 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
2 ms |
376 KB |
Output is correct |
24 |
Correct |
2 ms |
376 KB |
Output is correct |
25 |
Correct |
2 ms |
376 KB |
Output is correct |
26 |
Correct |
2 ms |
376 KB |
Output is correct |
27 |
Correct |
2 ms |
376 KB |
Output is correct |
28 |
Correct |
2 ms |
380 KB |
Output is correct |
29 |
Correct |
2 ms |
376 KB |
Output is correct |
30 |
Correct |
2 ms |
376 KB |
Output is correct |
31 |
Correct |
2 ms |
504 KB |
Output is correct |
32 |
Correct |
3 ms |
504 KB |
Output is correct |
33 |
Correct |
3 ms |
504 KB |
Output is correct |
34 |
Correct |
2 ms |
504 KB |
Output is correct |
35 |
Correct |
3 ms |
508 KB |
Output is correct |
36 |
Correct |
3 ms |
504 KB |
Output is correct |
37 |
Correct |
3 ms |
508 KB |
Output is correct |
38 |
Correct |
2 ms |
504 KB |
Output is correct |
39 |
Correct |
2 ms |
504 KB |
Output is correct |
40 |
Correct |
3 ms |
504 KB |
Output is correct |
41 |
Correct |
2 ms |
508 KB |
Output is correct |
42 |
Correct |
2 ms |
520 KB |
Output is correct |
43 |
Correct |
3 ms |
508 KB |
Output is correct |
44 |
Correct |
2 ms |
504 KB |
Output is correct |
45 |
Correct |
3 ms |
504 KB |
Output is correct |
46 |
Correct |
14 ms |
3896 KB |
Output is correct |
47 |
Correct |
21 ms |
4600 KB |
Output is correct |
48 |
Correct |
23 ms |
5112 KB |
Output is correct |
49 |
Correct |
23 ms |
5140 KB |
Output is correct |
50 |
Correct |
23 ms |
5240 KB |
Output is correct |
51 |
Correct |
25 ms |
5212 KB |
Output is correct |
52 |
Correct |
13 ms |
2808 KB |
Output is correct |
53 |
Correct |
9 ms |
1912 KB |
Output is correct |
54 |
Correct |
18 ms |
4472 KB |
Output is correct |
55 |
Correct |
24 ms |
5240 KB |
Output is correct |
56 |
Correct |
18 ms |
4728 KB |
Output is correct |
57 |
Correct |
18 ms |
4344 KB |
Output is correct |
58 |
Correct |
19 ms |
4600 KB |
Output is correct |
59 |
Correct |
19 ms |
4852 KB |
Output is correct |
60 |
Correct |
19 ms |
4828 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
380 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
348 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
380 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
396 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
420 KB |
Output is correct |
19 |
Correct |
2 ms |
424 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
2 ms |
376 KB |
Output is correct |
24 |
Correct |
2 ms |
376 KB |
Output is correct |
25 |
Correct |
2 ms |
376 KB |
Output is correct |
26 |
Correct |
2 ms |
376 KB |
Output is correct |
27 |
Correct |
2 ms |
376 KB |
Output is correct |
28 |
Correct |
2 ms |
380 KB |
Output is correct |
29 |
Correct |
2 ms |
376 KB |
Output is correct |
30 |
Correct |
2 ms |
376 KB |
Output is correct |
31 |
Correct |
2 ms |
504 KB |
Output is correct |
32 |
Correct |
3 ms |
504 KB |
Output is correct |
33 |
Correct |
3 ms |
504 KB |
Output is correct |
34 |
Correct |
2 ms |
504 KB |
Output is correct |
35 |
Correct |
3 ms |
508 KB |
Output is correct |
36 |
Correct |
3 ms |
504 KB |
Output is correct |
37 |
Correct |
3 ms |
508 KB |
Output is correct |
38 |
Correct |
2 ms |
504 KB |
Output is correct |
39 |
Correct |
2 ms |
504 KB |
Output is correct |
40 |
Correct |
3 ms |
504 KB |
Output is correct |
41 |
Correct |
2 ms |
508 KB |
Output is correct |
42 |
Correct |
2 ms |
520 KB |
Output is correct |
43 |
Correct |
3 ms |
508 KB |
Output is correct |
44 |
Correct |
2 ms |
504 KB |
Output is correct |
45 |
Correct |
3 ms |
504 KB |
Output is correct |
46 |
Correct |
14 ms |
3896 KB |
Output is correct |
47 |
Correct |
21 ms |
4600 KB |
Output is correct |
48 |
Correct |
23 ms |
5112 KB |
Output is correct |
49 |
Correct |
23 ms |
5140 KB |
Output is correct |
50 |
Correct |
23 ms |
5240 KB |
Output is correct |
51 |
Correct |
25 ms |
5212 KB |
Output is correct |
52 |
Correct |
13 ms |
2808 KB |
Output is correct |
53 |
Correct |
9 ms |
1912 KB |
Output is correct |
54 |
Correct |
18 ms |
4472 KB |
Output is correct |
55 |
Correct |
24 ms |
5240 KB |
Output is correct |
56 |
Correct |
18 ms |
4728 KB |
Output is correct |
57 |
Correct |
18 ms |
4344 KB |
Output is correct |
58 |
Correct |
19 ms |
4600 KB |
Output is correct |
59 |
Correct |
19 ms |
4852 KB |
Output is correct |
60 |
Correct |
19 ms |
4828 KB |
Output is correct |
61 |
Correct |
61 ms |
17992 KB |
Output is correct |
62 |
Correct |
83 ms |
19972 KB |
Output is correct |
63 |
Correct |
99 ms |
21112 KB |
Output is correct |
64 |
Correct |
112 ms |
24440 KB |
Output is correct |
65 |
Correct |
110 ms |
24768 KB |
Output is correct |
66 |
Correct |
119 ms |
24780 KB |
Output is correct |
67 |
Correct |
96 ms |
19944 KB |
Output is correct |
68 |
Correct |
48 ms |
10072 KB |
Output is correct |
69 |
Correct |
82 ms |
20984 KB |
Output is correct |
70 |
Correct |
113 ms |
24824 KB |
Output is correct |
71 |
Correct |
81 ms |
21880 KB |
Output is correct |
72 |
Correct |
90 ms |
20728 KB |
Output is correct |
73 |
Correct |
93 ms |
22300 KB |
Output is correct |
74 |
Correct |
94 ms |
23292 KB |
Output is correct |
75 |
Correct |
94 ms |
23220 KB |
Output is correct |