/*
Uruchamiamy samolot zwiadowczy ( + 500% do wzlamaniej )
/▄/ /█/ /◐/ /▐/ /▌/ /▀/ /░/ /🔥/ choose own style!
***IT'S OUR LONG WAY TO THE OIILLLL***
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░████████░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█████████░░░░░░░░░░░░░░░░░▌░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░◐◐◐█████████▀▀▀▀▀▀🔥░░░░░░░░███░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█████████░░░░░░░░░░░░░░░░░░░░▌░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█████████░░░░░░░░░░░░░░░░░░░░█▌░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░▄▄▀██████████████████████████████████████████████████
░░░░░░░░░░░░░░░░░░░░░░░░░░▄▄▄████▄████████ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ █████
░░░░░░░░░░░░░░░░░░░░░░░░░░░▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀█████████▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█████████░░░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░◐◐◐█████████▀▀▀▀▀▀🔥░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█████████░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█████████░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░████████░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░███████░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░██████░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█████░░░░░░░░░░░░░░░
*/
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/detail/standard_policies.hpp>'
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;template <typename T> using ordered_set = tree <T, null_type, less< T >, rb_tree_tag,tree_order_statistics_node_update>;
#define pb push_back
#define ll long long
#define ld long double
#define fi first
#define se second
//#define pi 3.14159265358979323846
#define pii pair < ll , int >
#define pipii pair< int, pair < int , int > >
#define siz(n) (int)(n.size())
#define TIME 1.0 * clock() / CLOCKS_PER_SEC
const int inf=1e9 + 7;
const ll inf18=1e18 + 7;
const int N=1e5 + 7;
const int MN = 2097152;
const int M = 1e9 + 7;
int k, n, m, st, en;
vector < pii > g[N];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#ifdef Estb_probitie
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int n;
cin >> n;
int a[n];
ll pref[n] = {};
for (int i = 0; i < n; ++i)
cin >> a[i];
pref[0] = a[0];
for (int i = 1; i < n; ++i)
pref[i] = pref[i - 1] + a[i];
int dp[n] = {};
int st[n] = {};
dp[0] = 1;
st[0] = 0;
int ans = 0;
for (int i = 0; i < n; ++i)
{
if (i)
if (dp[i] < dp[i - 1])
{
dp[i] = dp[i - 1];
st[i] = st[i - 1];
}
if (i)
if (dp[i] == dp[i - 1] && st[i - 1] > st[i])
st[i] = st[i - 1];
ans = max(ans, dp[i]);
ll ousum = pref[i];
if (st[i])
ousum -= pref[st[i] - 1];
int l = i + 1, r = n;
while(l < r)
{
int mid = (l + r) >> 1;
if (pref[mid] - pref[i] < ousum)
l = mid + 1; else r = mid;
}
if (l == n) continue;
dp[l] = dp[i] + 1;
st[l] = i + 1;
}
cout << ans;
}
Compilation message
segments.cpp:35:50: warning: missing terminating ' character
#include <ext/pb_ds/detail/standard_policies.hpp>'
^
segments.cpp:35:50: warning: extra tokens at end of #include directive
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2680 KB |
Output is correct |
2 |
Correct |
4 ms |
2680 KB |
Output is correct |
3 |
Correct |
4 ms |
2680 KB |
Output is correct |
4 |
Correct |
4 ms |
2680 KB |
Output is correct |
5 |
Correct |
4 ms |
2680 KB |
Output is correct |
6 |
Correct |
4 ms |
2680 KB |
Output is correct |
7 |
Correct |
4 ms |
2680 KB |
Output is correct |
8 |
Correct |
4 ms |
2680 KB |
Output is correct |
9 |
Correct |
4 ms |
2680 KB |
Output is correct |
10 |
Correct |
4 ms |
2680 KB |
Output is correct |
11 |
Correct |
4 ms |
2680 KB |
Output is correct |
12 |
Correct |
4 ms |
2680 KB |
Output is correct |
13 |
Correct |
4 ms |
2680 KB |
Output is correct |
14 |
Correct |
4 ms |
2680 KB |
Output is correct |
15 |
Correct |
4 ms |
2680 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2680 KB |
Output is correct |
2 |
Correct |
4 ms |
2680 KB |
Output is correct |
3 |
Correct |
4 ms |
2680 KB |
Output is correct |
4 |
Correct |
4 ms |
2680 KB |
Output is correct |
5 |
Correct |
4 ms |
2680 KB |
Output is correct |
6 |
Correct |
4 ms |
2680 KB |
Output is correct |
7 |
Correct |
4 ms |
2680 KB |
Output is correct |
8 |
Correct |
4 ms |
2680 KB |
Output is correct |
9 |
Correct |
4 ms |
2680 KB |
Output is correct |
10 |
Correct |
4 ms |
2680 KB |
Output is correct |
11 |
Correct |
4 ms |
2680 KB |
Output is correct |
12 |
Correct |
4 ms |
2680 KB |
Output is correct |
13 |
Correct |
4 ms |
2680 KB |
Output is correct |
14 |
Correct |
4 ms |
2680 KB |
Output is correct |
15 |
Correct |
4 ms |
2680 KB |
Output is correct |
16 |
Correct |
4 ms |
2680 KB |
Output is correct |
17 |
Correct |
4 ms |
2680 KB |
Output is correct |
18 |
Correct |
4 ms |
2680 KB |
Output is correct |
19 |
Correct |
4 ms |
2680 KB |
Output is correct |
20 |
Correct |
4 ms |
2680 KB |
Output is correct |
21 |
Correct |
4 ms |
2680 KB |
Output is correct |
22 |
Correct |
4 ms |
2680 KB |
Output is correct |
23 |
Correct |
4 ms |
2680 KB |
Output is correct |
24 |
Correct |
4 ms |
2680 KB |
Output is correct |
25 |
Correct |
4 ms |
2680 KB |
Output is correct |
26 |
Correct |
4 ms |
2680 KB |
Output is correct |
27 |
Correct |
4 ms |
2680 KB |
Output is correct |
28 |
Correct |
4 ms |
2680 KB |
Output is correct |
29 |
Correct |
4 ms |
2680 KB |
Output is correct |
30 |
Correct |
4 ms |
2680 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2680 KB |
Output is correct |
2 |
Correct |
4 ms |
2680 KB |
Output is correct |
3 |
Correct |
4 ms |
2680 KB |
Output is correct |
4 |
Correct |
4 ms |
2680 KB |
Output is correct |
5 |
Correct |
4 ms |
2680 KB |
Output is correct |
6 |
Correct |
4 ms |
2680 KB |
Output is correct |
7 |
Correct |
4 ms |
2680 KB |
Output is correct |
8 |
Correct |
4 ms |
2680 KB |
Output is correct |
9 |
Correct |
4 ms |
2680 KB |
Output is correct |
10 |
Correct |
4 ms |
2680 KB |
Output is correct |
11 |
Correct |
4 ms |
2680 KB |
Output is correct |
12 |
Correct |
4 ms |
2680 KB |
Output is correct |
13 |
Correct |
4 ms |
2680 KB |
Output is correct |
14 |
Correct |
4 ms |
2680 KB |
Output is correct |
15 |
Correct |
4 ms |
2680 KB |
Output is correct |
16 |
Correct |
4 ms |
2680 KB |
Output is correct |
17 |
Correct |
4 ms |
2680 KB |
Output is correct |
18 |
Correct |
4 ms |
2680 KB |
Output is correct |
19 |
Correct |
4 ms |
2680 KB |
Output is correct |
20 |
Correct |
4 ms |
2680 KB |
Output is correct |
21 |
Correct |
4 ms |
2680 KB |
Output is correct |
22 |
Correct |
4 ms |
2680 KB |
Output is correct |
23 |
Correct |
4 ms |
2680 KB |
Output is correct |
24 |
Correct |
4 ms |
2680 KB |
Output is correct |
25 |
Correct |
4 ms |
2680 KB |
Output is correct |
26 |
Correct |
4 ms |
2680 KB |
Output is correct |
27 |
Correct |
4 ms |
2680 KB |
Output is correct |
28 |
Correct |
4 ms |
2680 KB |
Output is correct |
29 |
Correct |
4 ms |
2680 KB |
Output is correct |
30 |
Correct |
4 ms |
2680 KB |
Output is correct |
31 |
Correct |
4 ms |
2812 KB |
Output is correct |
32 |
Correct |
5 ms |
2808 KB |
Output is correct |
33 |
Correct |
4 ms |
2808 KB |
Output is correct |
34 |
Correct |
5 ms |
2808 KB |
Output is correct |
35 |
Correct |
5 ms |
2808 KB |
Output is correct |
36 |
Correct |
5 ms |
2808 KB |
Output is correct |
37 |
Correct |
5 ms |
2680 KB |
Output is correct |
38 |
Correct |
5 ms |
2680 KB |
Output is correct |
39 |
Correct |
4 ms |
2808 KB |
Output is correct |
40 |
Correct |
5 ms |
2808 KB |
Output is correct |
41 |
Correct |
4 ms |
2680 KB |
Output is correct |
42 |
Correct |
5 ms |
2680 KB |
Output is correct |
43 |
Correct |
4 ms |
2724 KB |
Output is correct |
44 |
Correct |
4 ms |
2808 KB |
Output is correct |
45 |
Correct |
4 ms |
2808 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2680 KB |
Output is correct |
2 |
Correct |
4 ms |
2680 KB |
Output is correct |
3 |
Correct |
4 ms |
2680 KB |
Output is correct |
4 |
Correct |
4 ms |
2680 KB |
Output is correct |
5 |
Correct |
4 ms |
2680 KB |
Output is correct |
6 |
Correct |
4 ms |
2680 KB |
Output is correct |
7 |
Correct |
4 ms |
2680 KB |
Output is correct |
8 |
Correct |
4 ms |
2680 KB |
Output is correct |
9 |
Correct |
4 ms |
2680 KB |
Output is correct |
10 |
Correct |
4 ms |
2680 KB |
Output is correct |
11 |
Correct |
4 ms |
2680 KB |
Output is correct |
12 |
Correct |
4 ms |
2680 KB |
Output is correct |
13 |
Correct |
4 ms |
2680 KB |
Output is correct |
14 |
Correct |
4 ms |
2680 KB |
Output is correct |
15 |
Correct |
4 ms |
2680 KB |
Output is correct |
16 |
Correct |
4 ms |
2680 KB |
Output is correct |
17 |
Correct |
4 ms |
2680 KB |
Output is correct |
18 |
Correct |
4 ms |
2680 KB |
Output is correct |
19 |
Correct |
4 ms |
2680 KB |
Output is correct |
20 |
Correct |
4 ms |
2680 KB |
Output is correct |
21 |
Correct |
4 ms |
2680 KB |
Output is correct |
22 |
Correct |
4 ms |
2680 KB |
Output is correct |
23 |
Correct |
4 ms |
2680 KB |
Output is correct |
24 |
Correct |
4 ms |
2680 KB |
Output is correct |
25 |
Correct |
4 ms |
2680 KB |
Output is correct |
26 |
Correct |
4 ms |
2680 KB |
Output is correct |
27 |
Correct |
4 ms |
2680 KB |
Output is correct |
28 |
Correct |
4 ms |
2680 KB |
Output is correct |
29 |
Correct |
4 ms |
2680 KB |
Output is correct |
30 |
Correct |
4 ms |
2680 KB |
Output is correct |
31 |
Correct |
4 ms |
2812 KB |
Output is correct |
32 |
Correct |
5 ms |
2808 KB |
Output is correct |
33 |
Correct |
4 ms |
2808 KB |
Output is correct |
34 |
Correct |
5 ms |
2808 KB |
Output is correct |
35 |
Correct |
5 ms |
2808 KB |
Output is correct |
36 |
Correct |
5 ms |
2808 KB |
Output is correct |
37 |
Correct |
5 ms |
2680 KB |
Output is correct |
38 |
Correct |
5 ms |
2680 KB |
Output is correct |
39 |
Correct |
4 ms |
2808 KB |
Output is correct |
40 |
Correct |
5 ms |
2808 KB |
Output is correct |
41 |
Correct |
4 ms |
2680 KB |
Output is correct |
42 |
Correct |
5 ms |
2680 KB |
Output is correct |
43 |
Correct |
4 ms |
2724 KB |
Output is correct |
44 |
Correct |
4 ms |
2808 KB |
Output is correct |
45 |
Correct |
4 ms |
2808 KB |
Output is correct |
46 |
Correct |
17 ms |
5096 KB |
Output is correct |
47 |
Correct |
21 ms |
5100 KB |
Output is correct |
48 |
Correct |
22 ms |
5496 KB |
Output is correct |
49 |
Correct |
22 ms |
5624 KB |
Output is correct |
50 |
Correct |
22 ms |
5624 KB |
Output is correct |
51 |
Correct |
25 ms |
5624 KB |
Output is correct |
52 |
Correct |
15 ms |
4088 KB |
Output is correct |
53 |
Correct |
10 ms |
3576 KB |
Output is correct |
54 |
Correct |
17 ms |
4856 KB |
Output is correct |
55 |
Correct |
25 ms |
5624 KB |
Output is correct |
56 |
Correct |
17 ms |
5112 KB |
Output is correct |
57 |
Correct |
18 ms |
5012 KB |
Output is correct |
58 |
Correct |
19 ms |
5112 KB |
Output is correct |
59 |
Correct |
18 ms |
5240 KB |
Output is correct |
60 |
Correct |
19 ms |
5240 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2680 KB |
Output is correct |
2 |
Correct |
4 ms |
2680 KB |
Output is correct |
3 |
Correct |
4 ms |
2680 KB |
Output is correct |
4 |
Correct |
4 ms |
2680 KB |
Output is correct |
5 |
Correct |
4 ms |
2680 KB |
Output is correct |
6 |
Correct |
4 ms |
2680 KB |
Output is correct |
7 |
Correct |
4 ms |
2680 KB |
Output is correct |
8 |
Correct |
4 ms |
2680 KB |
Output is correct |
9 |
Correct |
4 ms |
2680 KB |
Output is correct |
10 |
Correct |
4 ms |
2680 KB |
Output is correct |
11 |
Correct |
4 ms |
2680 KB |
Output is correct |
12 |
Correct |
4 ms |
2680 KB |
Output is correct |
13 |
Correct |
4 ms |
2680 KB |
Output is correct |
14 |
Correct |
4 ms |
2680 KB |
Output is correct |
15 |
Correct |
4 ms |
2680 KB |
Output is correct |
16 |
Correct |
4 ms |
2680 KB |
Output is correct |
17 |
Correct |
4 ms |
2680 KB |
Output is correct |
18 |
Correct |
4 ms |
2680 KB |
Output is correct |
19 |
Correct |
4 ms |
2680 KB |
Output is correct |
20 |
Correct |
4 ms |
2680 KB |
Output is correct |
21 |
Correct |
4 ms |
2680 KB |
Output is correct |
22 |
Correct |
4 ms |
2680 KB |
Output is correct |
23 |
Correct |
4 ms |
2680 KB |
Output is correct |
24 |
Correct |
4 ms |
2680 KB |
Output is correct |
25 |
Correct |
4 ms |
2680 KB |
Output is correct |
26 |
Correct |
4 ms |
2680 KB |
Output is correct |
27 |
Correct |
4 ms |
2680 KB |
Output is correct |
28 |
Correct |
4 ms |
2680 KB |
Output is correct |
29 |
Correct |
4 ms |
2680 KB |
Output is correct |
30 |
Correct |
4 ms |
2680 KB |
Output is correct |
31 |
Correct |
4 ms |
2812 KB |
Output is correct |
32 |
Correct |
5 ms |
2808 KB |
Output is correct |
33 |
Correct |
4 ms |
2808 KB |
Output is correct |
34 |
Correct |
5 ms |
2808 KB |
Output is correct |
35 |
Correct |
5 ms |
2808 KB |
Output is correct |
36 |
Correct |
5 ms |
2808 KB |
Output is correct |
37 |
Correct |
5 ms |
2680 KB |
Output is correct |
38 |
Correct |
5 ms |
2680 KB |
Output is correct |
39 |
Correct |
4 ms |
2808 KB |
Output is correct |
40 |
Correct |
5 ms |
2808 KB |
Output is correct |
41 |
Correct |
4 ms |
2680 KB |
Output is correct |
42 |
Correct |
5 ms |
2680 KB |
Output is correct |
43 |
Correct |
4 ms |
2724 KB |
Output is correct |
44 |
Correct |
4 ms |
2808 KB |
Output is correct |
45 |
Correct |
4 ms |
2808 KB |
Output is correct |
46 |
Correct |
17 ms |
5096 KB |
Output is correct |
47 |
Correct |
21 ms |
5100 KB |
Output is correct |
48 |
Correct |
22 ms |
5496 KB |
Output is correct |
49 |
Correct |
22 ms |
5624 KB |
Output is correct |
50 |
Correct |
22 ms |
5624 KB |
Output is correct |
51 |
Correct |
25 ms |
5624 KB |
Output is correct |
52 |
Correct |
15 ms |
4088 KB |
Output is correct |
53 |
Correct |
10 ms |
3576 KB |
Output is correct |
54 |
Correct |
17 ms |
4856 KB |
Output is correct |
55 |
Correct |
25 ms |
5624 KB |
Output is correct |
56 |
Correct |
17 ms |
5112 KB |
Output is correct |
57 |
Correct |
18 ms |
5012 KB |
Output is correct |
58 |
Correct |
19 ms |
5112 KB |
Output is correct |
59 |
Correct |
18 ms |
5240 KB |
Output is correct |
60 |
Correct |
19 ms |
5240 KB |
Output is correct |
61 |
Correct |
75 ms |
14480 KB |
Output is correct |
62 |
Correct |
82 ms |
14428 KB |
Output is correct |
63 |
Correct |
94 ms |
14840 KB |
Output is correct |
64 |
Correct |
100 ms |
17016 KB |
Output is correct |
65 |
Correct |
94 ms |
17272 KB |
Output is correct |
66 |
Correct |
108 ms |
17272 KB |
Output is correct |
67 |
Correct |
89 ms |
14456 KB |
Output is correct |
68 |
Correct |
50 ms |
8696 KB |
Output is correct |
69 |
Correct |
74 ms |
13560 KB |
Output is correct |
70 |
Correct |
103 ms |
17400 KB |
Output is correct |
71 |
Correct |
69 ms |
14456 KB |
Output is correct |
72 |
Correct |
78 ms |
14740 KB |
Output is correct |
73 |
Correct |
80 ms |
15352 KB |
Output is correct |
74 |
Correct |
79 ms |
15736 KB |
Output is correct |
75 |
Correct |
80 ms |
15776 KB |
Output is correct |