#include <bits/stdc++.h>
using namespace std;
int a[500009];
long long rs[500009];
int main(){
int n;
scanf("%d",&n);
for(int i=0;i<n;i++){
scanf("%d",&a[i]);
rs[i+1]=rs[i]+a[i];
}
pair<int,int> res = {0,0};
pair<int,long long> dp;
priority_queue<pair<long long,pair<int,int> >,vector<pair<long long,pair<int,int> > >, greater< pair<long long,pair<int,int> > > > updates;
for(int i=1;i<=n;i++){
while(updates.size() && updates.top().first<=rs[i]){
pair<int,int> cur = updates.top().second;
updates.pop();
res = max(res,cur);
}
dp = {res.first,rs[res.second] - rs[i]};
dp.first++;
updates.push({rs[i]-dp.second,{dp.first,i}});
//cout << dp[i].first << ' ' << dp[i].second << '\n';
// cout << res.first << ' ' << res.second.first << ' ' << res.second.second << '\n';
}
printf("%d", dp.first);
}
Compilation message
segments.cpp: In function 'int main()':
segments.cpp:10:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&n);
~~~~~^~~~~~~~~
segments.cpp:12:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&a[i]);
~~~~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
256 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
5 ms |
256 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
256 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
5 ms |
256 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
16 |
Correct |
5 ms |
376 KB |
Output is correct |
17 |
Correct |
5 ms |
376 KB |
Output is correct |
18 |
Correct |
5 ms |
376 KB |
Output is correct |
19 |
Correct |
5 ms |
376 KB |
Output is correct |
20 |
Correct |
5 ms |
376 KB |
Output is correct |
21 |
Correct |
5 ms |
376 KB |
Output is correct |
22 |
Correct |
5 ms |
376 KB |
Output is correct |
23 |
Correct |
5 ms |
376 KB |
Output is correct |
24 |
Correct |
5 ms |
376 KB |
Output is correct |
25 |
Correct |
5 ms |
376 KB |
Output is correct |
26 |
Correct |
5 ms |
376 KB |
Output is correct |
27 |
Correct |
5 ms |
376 KB |
Output is correct |
28 |
Correct |
5 ms |
376 KB |
Output is correct |
29 |
Correct |
5 ms |
376 KB |
Output is correct |
30 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
256 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
5 ms |
256 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
16 |
Correct |
5 ms |
376 KB |
Output is correct |
17 |
Correct |
5 ms |
376 KB |
Output is correct |
18 |
Correct |
5 ms |
376 KB |
Output is correct |
19 |
Correct |
5 ms |
376 KB |
Output is correct |
20 |
Correct |
5 ms |
376 KB |
Output is correct |
21 |
Correct |
5 ms |
376 KB |
Output is correct |
22 |
Correct |
5 ms |
376 KB |
Output is correct |
23 |
Correct |
5 ms |
376 KB |
Output is correct |
24 |
Correct |
5 ms |
376 KB |
Output is correct |
25 |
Correct |
5 ms |
376 KB |
Output is correct |
26 |
Correct |
5 ms |
376 KB |
Output is correct |
27 |
Correct |
5 ms |
376 KB |
Output is correct |
28 |
Correct |
5 ms |
376 KB |
Output is correct |
29 |
Correct |
5 ms |
376 KB |
Output is correct |
30 |
Correct |
5 ms |
376 KB |
Output is correct |
31 |
Correct |
5 ms |
504 KB |
Output is correct |
32 |
Correct |
6 ms |
376 KB |
Output is correct |
33 |
Correct |
6 ms |
376 KB |
Output is correct |
34 |
Correct |
5 ms |
376 KB |
Output is correct |
35 |
Correct |
5 ms |
376 KB |
Output is correct |
36 |
Correct |
5 ms |
376 KB |
Output is correct |
37 |
Correct |
6 ms |
376 KB |
Output is correct |
38 |
Correct |
6 ms |
376 KB |
Output is correct |
39 |
Correct |
5 ms |
376 KB |
Output is correct |
40 |
Correct |
6 ms |
376 KB |
Output is correct |
41 |
Correct |
5 ms |
376 KB |
Output is correct |
42 |
Correct |
5 ms |
376 KB |
Output is correct |
43 |
Correct |
5 ms |
376 KB |
Output is correct |
44 |
Correct |
5 ms |
376 KB |
Output is correct |
45 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
256 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
5 ms |
256 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
16 |
Correct |
5 ms |
376 KB |
Output is correct |
17 |
Correct |
5 ms |
376 KB |
Output is correct |
18 |
Correct |
5 ms |
376 KB |
Output is correct |
19 |
Correct |
5 ms |
376 KB |
Output is correct |
20 |
Correct |
5 ms |
376 KB |
Output is correct |
21 |
Correct |
5 ms |
376 KB |
Output is correct |
22 |
Correct |
5 ms |
376 KB |
Output is correct |
23 |
Correct |
5 ms |
376 KB |
Output is correct |
24 |
Correct |
5 ms |
376 KB |
Output is correct |
25 |
Correct |
5 ms |
376 KB |
Output is correct |
26 |
Correct |
5 ms |
376 KB |
Output is correct |
27 |
Correct |
5 ms |
376 KB |
Output is correct |
28 |
Correct |
5 ms |
376 KB |
Output is correct |
29 |
Correct |
5 ms |
376 KB |
Output is correct |
30 |
Correct |
5 ms |
376 KB |
Output is correct |
31 |
Correct |
5 ms |
504 KB |
Output is correct |
32 |
Correct |
6 ms |
376 KB |
Output is correct |
33 |
Correct |
6 ms |
376 KB |
Output is correct |
34 |
Correct |
5 ms |
376 KB |
Output is correct |
35 |
Correct |
5 ms |
376 KB |
Output is correct |
36 |
Correct |
5 ms |
376 KB |
Output is correct |
37 |
Correct |
6 ms |
376 KB |
Output is correct |
38 |
Correct |
6 ms |
376 KB |
Output is correct |
39 |
Correct |
5 ms |
376 KB |
Output is correct |
40 |
Correct |
6 ms |
376 KB |
Output is correct |
41 |
Correct |
5 ms |
376 KB |
Output is correct |
42 |
Correct |
5 ms |
376 KB |
Output is correct |
43 |
Correct |
5 ms |
376 KB |
Output is correct |
44 |
Correct |
5 ms |
376 KB |
Output is correct |
45 |
Correct |
5 ms |
376 KB |
Output is correct |
46 |
Correct |
20 ms |
3820 KB |
Output is correct |
47 |
Correct |
29 ms |
2168 KB |
Output is correct |
48 |
Correct |
30 ms |
2040 KB |
Output is correct |
49 |
Correct |
27 ms |
2424 KB |
Output is correct |
50 |
Correct |
23 ms |
2044 KB |
Output is correct |
51 |
Correct |
34 ms |
2040 KB |
Output is correct |
52 |
Correct |
19 ms |
1016 KB |
Output is correct |
53 |
Correct |
13 ms |
760 KB |
Output is correct |
54 |
Correct |
25 ms |
1656 KB |
Output is correct |
55 |
Correct |
31 ms |
2040 KB |
Output is correct |
56 |
Correct |
20 ms |
1656 KB |
Output is correct |
57 |
Correct |
23 ms |
2800 KB |
Output is correct |
58 |
Correct |
26 ms |
2292 KB |
Output is correct |
59 |
Correct |
22 ms |
1656 KB |
Output is correct |
60 |
Correct |
26 ms |
1656 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
256 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
5 ms |
256 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
16 |
Correct |
5 ms |
376 KB |
Output is correct |
17 |
Correct |
5 ms |
376 KB |
Output is correct |
18 |
Correct |
5 ms |
376 KB |
Output is correct |
19 |
Correct |
5 ms |
376 KB |
Output is correct |
20 |
Correct |
5 ms |
376 KB |
Output is correct |
21 |
Correct |
5 ms |
376 KB |
Output is correct |
22 |
Correct |
5 ms |
376 KB |
Output is correct |
23 |
Correct |
5 ms |
376 KB |
Output is correct |
24 |
Correct |
5 ms |
376 KB |
Output is correct |
25 |
Correct |
5 ms |
376 KB |
Output is correct |
26 |
Correct |
5 ms |
376 KB |
Output is correct |
27 |
Correct |
5 ms |
376 KB |
Output is correct |
28 |
Correct |
5 ms |
376 KB |
Output is correct |
29 |
Correct |
5 ms |
376 KB |
Output is correct |
30 |
Correct |
5 ms |
376 KB |
Output is correct |
31 |
Correct |
5 ms |
504 KB |
Output is correct |
32 |
Correct |
6 ms |
376 KB |
Output is correct |
33 |
Correct |
6 ms |
376 KB |
Output is correct |
34 |
Correct |
5 ms |
376 KB |
Output is correct |
35 |
Correct |
5 ms |
376 KB |
Output is correct |
36 |
Correct |
5 ms |
376 KB |
Output is correct |
37 |
Correct |
6 ms |
376 KB |
Output is correct |
38 |
Correct |
6 ms |
376 KB |
Output is correct |
39 |
Correct |
5 ms |
376 KB |
Output is correct |
40 |
Correct |
6 ms |
376 KB |
Output is correct |
41 |
Correct |
5 ms |
376 KB |
Output is correct |
42 |
Correct |
5 ms |
376 KB |
Output is correct |
43 |
Correct |
5 ms |
376 KB |
Output is correct |
44 |
Correct |
5 ms |
376 KB |
Output is correct |
45 |
Correct |
5 ms |
376 KB |
Output is correct |
46 |
Correct |
20 ms |
3820 KB |
Output is correct |
47 |
Correct |
29 ms |
2168 KB |
Output is correct |
48 |
Correct |
30 ms |
2040 KB |
Output is correct |
49 |
Correct |
27 ms |
2424 KB |
Output is correct |
50 |
Correct |
23 ms |
2044 KB |
Output is correct |
51 |
Correct |
34 ms |
2040 KB |
Output is correct |
52 |
Correct |
19 ms |
1016 KB |
Output is correct |
53 |
Correct |
13 ms |
760 KB |
Output is correct |
54 |
Correct |
25 ms |
1656 KB |
Output is correct |
55 |
Correct |
31 ms |
2040 KB |
Output is correct |
56 |
Correct |
20 ms |
1656 KB |
Output is correct |
57 |
Correct |
23 ms |
2800 KB |
Output is correct |
58 |
Correct |
26 ms |
2292 KB |
Output is correct |
59 |
Correct |
22 ms |
1656 KB |
Output is correct |
60 |
Correct |
26 ms |
1656 KB |
Output is correct |
61 |
Correct |
78 ms |
15324 KB |
Output is correct |
62 |
Correct |
97 ms |
10628 KB |
Output is correct |
63 |
Correct |
123 ms |
9192 KB |
Output is correct |
64 |
Correct |
122 ms |
10872 KB |
Output is correct |
65 |
Correct |
102 ms |
11128 KB |
Output is correct |
66 |
Correct |
162 ms |
11004 KB |
Output is correct |
67 |
Correct |
125 ms |
8952 KB |
Output is correct |
68 |
Correct |
64 ms |
4600 KB |
Output is correct |
69 |
Correct |
110 ms |
7288 KB |
Output is correct |
70 |
Correct |
134 ms |
11128 KB |
Output is correct |
71 |
Correct |
80 ms |
8184 KB |
Output is correct |
72 |
Correct |
103 ms |
12772 KB |
Output is correct |
73 |
Correct |
96 ms |
11372 KB |
Output is correct |
74 |
Correct |
86 ms |
9592 KB |
Output is correct |
75 |
Correct |
91 ms |
9592 KB |
Output is correct |