/*
Uruchamiamy samolot zwiadowczy ( + 500% do wzlamaniej )
/▄/ /█/ /🔥/ /▐/ /▌/ /▀/ /░/ /◐ / choose your 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 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
mt19937 gen(chrono::high_resolution_clock::now().time_since_epoch().count());
const int inf=1e9 + 7;
const ll inf18=1e18 + 7;
const int N=1e6 + 7;
const int MN = 2097152;
const int M = 1e9 + 7;
ll dp[3001][3001];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
srand(time(0));
#ifdef Estb_probitie
freopen("input.txt", "r", stdin);
freopen("output1.txt", "w", stdout);
#endif
int n;
cin >> n;
int a[n];
for (int i = 0; i < n; ++i)
cin >> a[i];
ll pref[n];
pref[0] = a[0];
for (int i = 1; i < n; ++i)
pref[i] = pref[i - 1] + a[i];
for (int i = 0; i < n; ++i)
fill(dp[i], dp[i] + n + 1, 1e17);
dp[0][1] = a[0];
ll nac[n + 2] = {};
fill(nac, nac + n + 1, 1e9);
nac[1] = 0;
for (int i = 1; i < n; ++i)
{
bool byl = 1;
for (int j = 1; j <= i + 1; ++j)
{
dp[i][j] = min(dp[i][j], a[i] + dp[i - 1][j]);
if (nac[j - 1] == 1e9) continue;
int l = nac[j - 1], r = i - 1;
while(l < r)
{
int mid = ((l + r) >> 1) + 1;
if (pref[i] - pref[mid] >= dp[mid][j - 1])
l = mid; else
r = mid - 1;
}
for (int l2 = max(0, l - 50); l2 <= min(i - 1, l + 50); ++l2)
if (pref[i] - pref[l2] >= dp[l2][j - 1])
{
dp[i][j] = min(dp[i][j], pref[i] - pref[l2]);
nac[j] = min(nac[j], 1ll * i);
//// cout<<i<<" "<<j<<" "<<l<<endl;
}
}
}
int ans = 0;
for (int j = 1; j <= n; ++j)
if (dp[n - 1][j] < 1e16)
{
ans = j;
}
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
segments.cpp: In function 'int main()':
segments.cpp:91:14: warning: unused variable 'byl' [-Wunused-variable]
bool byl = 1;
^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 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 |
504 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 |
376 KB |
Output is correct |
9 |
Correct |
3 ms |
504 KB |
Output is correct |
10 |
Correct |
2 ms |
504 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
424 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 |
376 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 |
504 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 |
376 KB |
Output is correct |
9 |
Correct |
3 ms |
504 KB |
Output is correct |
10 |
Correct |
2 ms |
504 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
424 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 |
6 ms |
4348 KB |
Output is correct |
17 |
Correct |
7 ms |
4344 KB |
Output is correct |
18 |
Correct |
11 ms |
4344 KB |
Output is correct |
19 |
Correct |
30 ms |
4412 KB |
Output is correct |
20 |
Correct |
29 ms |
4344 KB |
Output is correct |
21 |
Correct |
9 ms |
4348 KB |
Output is correct |
22 |
Correct |
7 ms |
3144 KB |
Output is correct |
23 |
Correct |
5 ms |
2296 KB |
Output is correct |
24 |
Correct |
10 ms |
4368 KB |
Output is correct |
25 |
Correct |
9 ms |
4316 KB |
Output is correct |
26 |
Correct |
37 ms |
4348 KB |
Output is correct |
27 |
Correct |
22 ms |
4344 KB |
Output is correct |
28 |
Correct |
11 ms |
4344 KB |
Output is correct |
29 |
Correct |
28 ms |
4344 KB |
Output is correct |
30 |
Correct |
29 ms |
4344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 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 |
504 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 |
376 KB |
Output is correct |
9 |
Correct |
3 ms |
504 KB |
Output is correct |
10 |
Correct |
2 ms |
504 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
424 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 |
6 ms |
4348 KB |
Output is correct |
17 |
Correct |
7 ms |
4344 KB |
Output is correct |
18 |
Correct |
11 ms |
4344 KB |
Output is correct |
19 |
Correct |
30 ms |
4412 KB |
Output is correct |
20 |
Correct |
29 ms |
4344 KB |
Output is correct |
21 |
Correct |
9 ms |
4348 KB |
Output is correct |
22 |
Correct |
7 ms |
3144 KB |
Output is correct |
23 |
Correct |
5 ms |
2296 KB |
Output is correct |
24 |
Correct |
10 ms |
4368 KB |
Output is correct |
25 |
Correct |
9 ms |
4316 KB |
Output is correct |
26 |
Correct |
37 ms |
4348 KB |
Output is correct |
27 |
Correct |
22 ms |
4344 KB |
Output is correct |
28 |
Correct |
11 ms |
4344 KB |
Output is correct |
29 |
Correct |
28 ms |
4344 KB |
Output is correct |
30 |
Correct |
29 ms |
4344 KB |
Output is correct |
31 |
Correct |
77 ms |
70904 KB |
Output is correct |
32 |
Correct |
82 ms |
71048 KB |
Output is correct |
33 |
Correct |
172 ms |
70952 KB |
Output is correct |
34 |
Correct |
1174 ms |
70956 KB |
Output is correct |
35 |
Correct |
1085 ms |
70944 KB |
Output is correct |
36 |
Correct |
139 ms |
70904 KB |
Output is correct |
37 |
Correct |
111 ms |
59232 KB |
Output is correct |
38 |
Correct |
78 ms |
39800 KB |
Output is correct |
39 |
Correct |
149 ms |
71032 KB |
Output is correct |
40 |
Correct |
140 ms |
71032 KB |
Output is correct |
41 |
Correct |
1138 ms |
70964 KB |
Output is correct |
42 |
Correct |
1065 ms |
71032 KB |
Output is correct |
43 |
Correct |
367 ms |
70936 KB |
Output is correct |
44 |
Correct |
1079 ms |
71032 KB |
Output is correct |
45 |
Correct |
1153 ms |
70932 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 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 |
504 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 |
376 KB |
Output is correct |
9 |
Correct |
3 ms |
504 KB |
Output is correct |
10 |
Correct |
2 ms |
504 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
424 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 |
6 ms |
4348 KB |
Output is correct |
17 |
Correct |
7 ms |
4344 KB |
Output is correct |
18 |
Correct |
11 ms |
4344 KB |
Output is correct |
19 |
Correct |
30 ms |
4412 KB |
Output is correct |
20 |
Correct |
29 ms |
4344 KB |
Output is correct |
21 |
Correct |
9 ms |
4348 KB |
Output is correct |
22 |
Correct |
7 ms |
3144 KB |
Output is correct |
23 |
Correct |
5 ms |
2296 KB |
Output is correct |
24 |
Correct |
10 ms |
4368 KB |
Output is correct |
25 |
Correct |
9 ms |
4316 KB |
Output is correct |
26 |
Correct |
37 ms |
4348 KB |
Output is correct |
27 |
Correct |
22 ms |
4344 KB |
Output is correct |
28 |
Correct |
11 ms |
4344 KB |
Output is correct |
29 |
Correct |
28 ms |
4344 KB |
Output is correct |
30 |
Correct |
29 ms |
4344 KB |
Output is correct |
31 |
Correct |
77 ms |
70904 KB |
Output is correct |
32 |
Correct |
82 ms |
71048 KB |
Output is correct |
33 |
Correct |
172 ms |
70952 KB |
Output is correct |
34 |
Correct |
1174 ms |
70956 KB |
Output is correct |
35 |
Correct |
1085 ms |
70944 KB |
Output is correct |
36 |
Correct |
139 ms |
70904 KB |
Output is correct |
37 |
Correct |
111 ms |
59232 KB |
Output is correct |
38 |
Correct |
78 ms |
39800 KB |
Output is correct |
39 |
Correct |
149 ms |
71032 KB |
Output is correct |
40 |
Correct |
140 ms |
71032 KB |
Output is correct |
41 |
Correct |
1138 ms |
70964 KB |
Output is correct |
42 |
Correct |
1065 ms |
71032 KB |
Output is correct |
43 |
Correct |
367 ms |
70936 KB |
Output is correct |
44 |
Correct |
1079 ms |
71032 KB |
Output is correct |
45 |
Correct |
1153 ms |
70932 KB |
Output is correct |
46 |
Runtime error |
334 ms |
146152 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
47 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 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 |
504 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 |
376 KB |
Output is correct |
9 |
Correct |
3 ms |
504 KB |
Output is correct |
10 |
Correct |
2 ms |
504 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
424 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 |
6 ms |
4348 KB |
Output is correct |
17 |
Correct |
7 ms |
4344 KB |
Output is correct |
18 |
Correct |
11 ms |
4344 KB |
Output is correct |
19 |
Correct |
30 ms |
4412 KB |
Output is correct |
20 |
Correct |
29 ms |
4344 KB |
Output is correct |
21 |
Correct |
9 ms |
4348 KB |
Output is correct |
22 |
Correct |
7 ms |
3144 KB |
Output is correct |
23 |
Correct |
5 ms |
2296 KB |
Output is correct |
24 |
Correct |
10 ms |
4368 KB |
Output is correct |
25 |
Correct |
9 ms |
4316 KB |
Output is correct |
26 |
Correct |
37 ms |
4348 KB |
Output is correct |
27 |
Correct |
22 ms |
4344 KB |
Output is correct |
28 |
Correct |
11 ms |
4344 KB |
Output is correct |
29 |
Correct |
28 ms |
4344 KB |
Output is correct |
30 |
Correct |
29 ms |
4344 KB |
Output is correct |
31 |
Correct |
77 ms |
70904 KB |
Output is correct |
32 |
Correct |
82 ms |
71048 KB |
Output is correct |
33 |
Correct |
172 ms |
70952 KB |
Output is correct |
34 |
Correct |
1174 ms |
70956 KB |
Output is correct |
35 |
Correct |
1085 ms |
70944 KB |
Output is correct |
36 |
Correct |
139 ms |
70904 KB |
Output is correct |
37 |
Correct |
111 ms |
59232 KB |
Output is correct |
38 |
Correct |
78 ms |
39800 KB |
Output is correct |
39 |
Correct |
149 ms |
71032 KB |
Output is correct |
40 |
Correct |
140 ms |
71032 KB |
Output is correct |
41 |
Correct |
1138 ms |
70964 KB |
Output is correct |
42 |
Correct |
1065 ms |
71032 KB |
Output is correct |
43 |
Correct |
367 ms |
70936 KB |
Output is correct |
44 |
Correct |
1079 ms |
71032 KB |
Output is correct |
45 |
Correct |
1153 ms |
70932 KB |
Output is correct |
46 |
Runtime error |
334 ms |
146152 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
47 |
Halted |
0 ms |
0 KB |
- |