#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll INF=2e17;
const int MAXN=5e5+6;
ll a[MAXN],n;
ll pref[MAXN];
ll dp[MAXN],s[MAXN];
vector<pair<ll,ll> >v[MAXN];
int main()
{
cin>>n;
for(int i=1;i<=n;i++)cin>>a[i];
for(int i=1;i<=n;i++)
{
pref[i]=pref[i-1]+a[i];
}
dp[0]=0;s[0]=0;
priority_queue<pair<ll,ll> >pq;
pq.push({0,0});
priority_queue<pair<pair<ll,ll>,ll> >to_add;
for(int i=1;i<=n;i++)
{
while(!to_add.empty()&&-to_add.top().first.first<=pref[i])
{
pq.push({to_add.top().first.second,to_add.top().second});
to_add.pop();
}
auto t=pq.top();
dp[i]=t.first+1;
to_add.push({{-2*pref[i]+pref[t.second],dp[i]},i});
}
cout<<dp[n]<<endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
12140 KB |
Output is correct |
2 |
Correct |
9 ms |
12140 KB |
Output is correct |
3 |
Correct |
9 ms |
12140 KB |
Output is correct |
4 |
Correct |
10 ms |
12140 KB |
Output is correct |
5 |
Correct |
9 ms |
12140 KB |
Output is correct |
6 |
Correct |
9 ms |
12288 KB |
Output is correct |
7 |
Correct |
9 ms |
12140 KB |
Output is correct |
8 |
Correct |
9 ms |
12140 KB |
Output is correct |
9 |
Correct |
8 ms |
12140 KB |
Output is correct |
10 |
Correct |
9 ms |
12140 KB |
Output is correct |
11 |
Correct |
10 ms |
12140 KB |
Output is correct |
12 |
Correct |
9 ms |
12140 KB |
Output is correct |
13 |
Correct |
9 ms |
12140 KB |
Output is correct |
14 |
Correct |
8 ms |
12140 KB |
Output is correct |
15 |
Correct |
9 ms |
12288 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
12140 KB |
Output is correct |
2 |
Correct |
9 ms |
12140 KB |
Output is correct |
3 |
Correct |
9 ms |
12140 KB |
Output is correct |
4 |
Correct |
10 ms |
12140 KB |
Output is correct |
5 |
Correct |
9 ms |
12140 KB |
Output is correct |
6 |
Correct |
9 ms |
12288 KB |
Output is correct |
7 |
Correct |
9 ms |
12140 KB |
Output is correct |
8 |
Correct |
9 ms |
12140 KB |
Output is correct |
9 |
Correct |
8 ms |
12140 KB |
Output is correct |
10 |
Correct |
9 ms |
12140 KB |
Output is correct |
11 |
Correct |
10 ms |
12140 KB |
Output is correct |
12 |
Correct |
9 ms |
12140 KB |
Output is correct |
13 |
Correct |
9 ms |
12140 KB |
Output is correct |
14 |
Correct |
8 ms |
12140 KB |
Output is correct |
15 |
Correct |
9 ms |
12288 KB |
Output is correct |
16 |
Correct |
9 ms |
12140 KB |
Output is correct |
17 |
Correct |
11 ms |
12140 KB |
Output is correct |
18 |
Correct |
11 ms |
12140 KB |
Output is correct |
19 |
Correct |
9 ms |
12140 KB |
Output is correct |
20 |
Correct |
9 ms |
12140 KB |
Output is correct |
21 |
Correct |
9 ms |
12140 KB |
Output is correct |
22 |
Correct |
10 ms |
12140 KB |
Output is correct |
23 |
Correct |
9 ms |
12140 KB |
Output is correct |
24 |
Correct |
9 ms |
12140 KB |
Output is correct |
25 |
Correct |
9 ms |
12140 KB |
Output is correct |
26 |
Correct |
10 ms |
12140 KB |
Output is correct |
27 |
Correct |
10 ms |
12288 KB |
Output is correct |
28 |
Correct |
11 ms |
12140 KB |
Output is correct |
29 |
Correct |
9 ms |
12140 KB |
Output is correct |
30 |
Correct |
9 ms |
12140 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
12140 KB |
Output is correct |
2 |
Correct |
9 ms |
12140 KB |
Output is correct |
3 |
Correct |
9 ms |
12140 KB |
Output is correct |
4 |
Correct |
10 ms |
12140 KB |
Output is correct |
5 |
Correct |
9 ms |
12140 KB |
Output is correct |
6 |
Correct |
9 ms |
12288 KB |
Output is correct |
7 |
Correct |
9 ms |
12140 KB |
Output is correct |
8 |
Correct |
9 ms |
12140 KB |
Output is correct |
9 |
Correct |
8 ms |
12140 KB |
Output is correct |
10 |
Correct |
9 ms |
12140 KB |
Output is correct |
11 |
Correct |
10 ms |
12140 KB |
Output is correct |
12 |
Correct |
9 ms |
12140 KB |
Output is correct |
13 |
Correct |
9 ms |
12140 KB |
Output is correct |
14 |
Correct |
8 ms |
12140 KB |
Output is correct |
15 |
Correct |
9 ms |
12288 KB |
Output is correct |
16 |
Correct |
9 ms |
12140 KB |
Output is correct |
17 |
Correct |
11 ms |
12140 KB |
Output is correct |
18 |
Correct |
11 ms |
12140 KB |
Output is correct |
19 |
Correct |
9 ms |
12140 KB |
Output is correct |
20 |
Correct |
9 ms |
12140 KB |
Output is correct |
21 |
Correct |
9 ms |
12140 KB |
Output is correct |
22 |
Correct |
10 ms |
12140 KB |
Output is correct |
23 |
Correct |
9 ms |
12140 KB |
Output is correct |
24 |
Correct |
9 ms |
12140 KB |
Output is correct |
25 |
Correct |
9 ms |
12140 KB |
Output is correct |
26 |
Correct |
10 ms |
12140 KB |
Output is correct |
27 |
Correct |
10 ms |
12288 KB |
Output is correct |
28 |
Correct |
11 ms |
12140 KB |
Output is correct |
29 |
Correct |
9 ms |
12140 KB |
Output is correct |
30 |
Correct |
9 ms |
12140 KB |
Output is correct |
31 |
Correct |
9 ms |
12396 KB |
Output is correct |
32 |
Correct |
10 ms |
12268 KB |
Output is correct |
33 |
Correct |
10 ms |
12268 KB |
Output is correct |
34 |
Correct |
10 ms |
12284 KB |
Output is correct |
35 |
Correct |
10 ms |
12268 KB |
Output is correct |
36 |
Correct |
12 ms |
12268 KB |
Output is correct |
37 |
Correct |
10 ms |
12268 KB |
Output is correct |
38 |
Correct |
10 ms |
12268 KB |
Output is correct |
39 |
Correct |
10 ms |
12268 KB |
Output is correct |
40 |
Correct |
11 ms |
12396 KB |
Output is correct |
41 |
Correct |
9 ms |
12268 KB |
Output is correct |
42 |
Correct |
10 ms |
12396 KB |
Output is correct |
43 |
Correct |
10 ms |
12268 KB |
Output is correct |
44 |
Correct |
10 ms |
12268 KB |
Output is correct |
45 |
Correct |
10 ms |
12268 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
12140 KB |
Output is correct |
2 |
Correct |
9 ms |
12140 KB |
Output is correct |
3 |
Correct |
9 ms |
12140 KB |
Output is correct |
4 |
Correct |
10 ms |
12140 KB |
Output is correct |
5 |
Correct |
9 ms |
12140 KB |
Output is correct |
6 |
Correct |
9 ms |
12288 KB |
Output is correct |
7 |
Correct |
9 ms |
12140 KB |
Output is correct |
8 |
Correct |
9 ms |
12140 KB |
Output is correct |
9 |
Correct |
8 ms |
12140 KB |
Output is correct |
10 |
Correct |
9 ms |
12140 KB |
Output is correct |
11 |
Correct |
10 ms |
12140 KB |
Output is correct |
12 |
Correct |
9 ms |
12140 KB |
Output is correct |
13 |
Correct |
9 ms |
12140 KB |
Output is correct |
14 |
Correct |
8 ms |
12140 KB |
Output is correct |
15 |
Correct |
9 ms |
12288 KB |
Output is correct |
16 |
Correct |
9 ms |
12140 KB |
Output is correct |
17 |
Correct |
11 ms |
12140 KB |
Output is correct |
18 |
Correct |
11 ms |
12140 KB |
Output is correct |
19 |
Correct |
9 ms |
12140 KB |
Output is correct |
20 |
Correct |
9 ms |
12140 KB |
Output is correct |
21 |
Correct |
9 ms |
12140 KB |
Output is correct |
22 |
Correct |
10 ms |
12140 KB |
Output is correct |
23 |
Correct |
9 ms |
12140 KB |
Output is correct |
24 |
Correct |
9 ms |
12140 KB |
Output is correct |
25 |
Correct |
9 ms |
12140 KB |
Output is correct |
26 |
Correct |
10 ms |
12140 KB |
Output is correct |
27 |
Correct |
10 ms |
12288 KB |
Output is correct |
28 |
Correct |
11 ms |
12140 KB |
Output is correct |
29 |
Correct |
9 ms |
12140 KB |
Output is correct |
30 |
Correct |
9 ms |
12140 KB |
Output is correct |
31 |
Correct |
9 ms |
12396 KB |
Output is correct |
32 |
Correct |
10 ms |
12268 KB |
Output is correct |
33 |
Correct |
10 ms |
12268 KB |
Output is correct |
34 |
Correct |
10 ms |
12284 KB |
Output is correct |
35 |
Correct |
10 ms |
12268 KB |
Output is correct |
36 |
Correct |
12 ms |
12268 KB |
Output is correct |
37 |
Correct |
10 ms |
12268 KB |
Output is correct |
38 |
Correct |
10 ms |
12268 KB |
Output is correct |
39 |
Correct |
10 ms |
12268 KB |
Output is correct |
40 |
Correct |
11 ms |
12396 KB |
Output is correct |
41 |
Correct |
9 ms |
12268 KB |
Output is correct |
42 |
Correct |
10 ms |
12396 KB |
Output is correct |
43 |
Correct |
10 ms |
12268 KB |
Output is correct |
44 |
Correct |
10 ms |
12268 KB |
Output is correct |
45 |
Correct |
10 ms |
12268 KB |
Output is correct |
46 |
Correct |
36 ms |
17760 KB |
Output is correct |
47 |
Correct |
55 ms |
17056 KB |
Output is correct |
48 |
Correct |
62 ms |
17140 KB |
Output is correct |
49 |
Correct |
58 ms |
17372 KB |
Output is correct |
50 |
Correct |
59 ms |
17376 KB |
Output is correct |
51 |
Correct |
80 ms |
17376 KB |
Output is correct |
52 |
Correct |
40 ms |
14968 KB |
Output is correct |
53 |
Correct |
26 ms |
13672 KB |
Output is correct |
54 |
Correct |
43 ms |
16608 KB |
Output is correct |
55 |
Correct |
70 ms |
17376 KB |
Output is correct |
56 |
Correct |
44 ms |
16864 KB |
Output is correct |
57 |
Correct |
49 ms |
18780 KB |
Output is correct |
58 |
Correct |
50 ms |
17628 KB |
Output is correct |
59 |
Correct |
45 ms |
16888 KB |
Output is correct |
60 |
Correct |
50 ms |
16864 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
12140 KB |
Output is correct |
2 |
Correct |
9 ms |
12140 KB |
Output is correct |
3 |
Correct |
9 ms |
12140 KB |
Output is correct |
4 |
Correct |
10 ms |
12140 KB |
Output is correct |
5 |
Correct |
9 ms |
12140 KB |
Output is correct |
6 |
Correct |
9 ms |
12288 KB |
Output is correct |
7 |
Correct |
9 ms |
12140 KB |
Output is correct |
8 |
Correct |
9 ms |
12140 KB |
Output is correct |
9 |
Correct |
8 ms |
12140 KB |
Output is correct |
10 |
Correct |
9 ms |
12140 KB |
Output is correct |
11 |
Correct |
10 ms |
12140 KB |
Output is correct |
12 |
Correct |
9 ms |
12140 KB |
Output is correct |
13 |
Correct |
9 ms |
12140 KB |
Output is correct |
14 |
Correct |
8 ms |
12140 KB |
Output is correct |
15 |
Correct |
9 ms |
12288 KB |
Output is correct |
16 |
Correct |
9 ms |
12140 KB |
Output is correct |
17 |
Correct |
11 ms |
12140 KB |
Output is correct |
18 |
Correct |
11 ms |
12140 KB |
Output is correct |
19 |
Correct |
9 ms |
12140 KB |
Output is correct |
20 |
Correct |
9 ms |
12140 KB |
Output is correct |
21 |
Correct |
9 ms |
12140 KB |
Output is correct |
22 |
Correct |
10 ms |
12140 KB |
Output is correct |
23 |
Correct |
9 ms |
12140 KB |
Output is correct |
24 |
Correct |
9 ms |
12140 KB |
Output is correct |
25 |
Correct |
9 ms |
12140 KB |
Output is correct |
26 |
Correct |
10 ms |
12140 KB |
Output is correct |
27 |
Correct |
10 ms |
12288 KB |
Output is correct |
28 |
Correct |
11 ms |
12140 KB |
Output is correct |
29 |
Correct |
9 ms |
12140 KB |
Output is correct |
30 |
Correct |
9 ms |
12140 KB |
Output is correct |
31 |
Correct |
9 ms |
12396 KB |
Output is correct |
32 |
Correct |
10 ms |
12268 KB |
Output is correct |
33 |
Correct |
10 ms |
12268 KB |
Output is correct |
34 |
Correct |
10 ms |
12284 KB |
Output is correct |
35 |
Correct |
10 ms |
12268 KB |
Output is correct |
36 |
Correct |
12 ms |
12268 KB |
Output is correct |
37 |
Correct |
10 ms |
12268 KB |
Output is correct |
38 |
Correct |
10 ms |
12268 KB |
Output is correct |
39 |
Correct |
10 ms |
12268 KB |
Output is correct |
40 |
Correct |
11 ms |
12396 KB |
Output is correct |
41 |
Correct |
9 ms |
12268 KB |
Output is correct |
42 |
Correct |
10 ms |
12396 KB |
Output is correct |
43 |
Correct |
10 ms |
12268 KB |
Output is correct |
44 |
Correct |
10 ms |
12268 KB |
Output is correct |
45 |
Correct |
10 ms |
12268 KB |
Output is correct |
46 |
Correct |
36 ms |
17760 KB |
Output is correct |
47 |
Correct |
55 ms |
17056 KB |
Output is correct |
48 |
Correct |
62 ms |
17140 KB |
Output is correct |
49 |
Correct |
58 ms |
17372 KB |
Output is correct |
50 |
Correct |
59 ms |
17376 KB |
Output is correct |
51 |
Correct |
80 ms |
17376 KB |
Output is correct |
52 |
Correct |
40 ms |
14968 KB |
Output is correct |
53 |
Correct |
26 ms |
13672 KB |
Output is correct |
54 |
Correct |
43 ms |
16608 KB |
Output is correct |
55 |
Correct |
70 ms |
17376 KB |
Output is correct |
56 |
Correct |
44 ms |
16864 KB |
Output is correct |
57 |
Correct |
49 ms |
18780 KB |
Output is correct |
58 |
Correct |
50 ms |
17628 KB |
Output is correct |
59 |
Correct |
45 ms |
16888 KB |
Output is correct |
60 |
Correct |
50 ms |
16864 KB |
Output is correct |
61 |
Correct |
161 ms |
37740 KB |
Output is correct |
62 |
Correct |
195 ms |
39756 KB |
Output is correct |
63 |
Correct |
249 ms |
36420 KB |
Output is correct |
64 |
Correct |
279 ms |
36304 KB |
Output is correct |
65 |
Correct |
261 ms |
36688 KB |
Output is correct |
66 |
Correct |
309 ms |
36552 KB |
Output is correct |
67 |
Correct |
258 ms |
32604 KB |
Output is correct |
68 |
Correct |
129 ms |
22364 KB |
Output is correct |
69 |
Correct |
188 ms |
32840 KB |
Output is correct |
70 |
Correct |
314 ms |
36760 KB |
Output is correct |
71 |
Correct |
166 ms |
33748 KB |
Output is correct |
72 |
Correct |
204 ms |
41792 KB |
Output is correct |
73 |
Correct |
210 ms |
39368 KB |
Output is correct |
74 |
Correct |
208 ms |
35156 KB |
Output is correct |
75 |
Correct |
215 ms |
35016 KB |
Output is correct |