#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define fi first
#define se second
const int N = 505;
const int mod = 998244353;
using namespace std;
const long long inf = 1e18;
int n;
int a[N];
long long s[N];
long long d[N][N];
int main() {
ios_base::sync_with_stdio(0);
#ifdef zxc
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
s[i] = s[i - 1] + a[i];
d[0][i] = inf;
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
d[i][j] = inf;
}
d[i][1] = s[i];
for (int j = 2; j <= i; j++) {
for (int h = i; h >= 1; h--) {
if (d[h - 1][j - 1] <= s[i] - s[h - 1]) {
d[i][j] = min(d[i][j], s[i] - s[h - 1]);
}
}
}
}
int res = n;
while (d[n][res] == inf) {
res -= 1;
}
cout << res << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
604 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
604 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
604 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
604 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
44 ms |
2388 KB |
Output is correct |
17 |
Correct |
44 ms |
2392 KB |
Output is correct |
18 |
Correct |
54 ms |
2364 KB |
Output is correct |
19 |
Correct |
65 ms |
2384 KB |
Output is correct |
20 |
Correct |
76 ms |
2412 KB |
Output is correct |
21 |
Correct |
47 ms |
2392 KB |
Output is correct |
22 |
Correct |
28 ms |
1884 KB |
Output is correct |
23 |
Correct |
11 ms |
1628 KB |
Output is correct |
24 |
Correct |
47 ms |
2224 KB |
Output is correct |
25 |
Correct |
49 ms |
2384 KB |
Output is correct |
26 |
Correct |
81 ms |
2384 KB |
Output is correct |
27 |
Correct |
51 ms |
2328 KB |
Output is correct |
28 |
Correct |
51 ms |
2388 KB |
Output is correct |
29 |
Correct |
76 ms |
2388 KB |
Output is correct |
30 |
Correct |
73 ms |
2388 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
604 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
604 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
44 ms |
2388 KB |
Output is correct |
17 |
Correct |
44 ms |
2392 KB |
Output is correct |
18 |
Correct |
54 ms |
2364 KB |
Output is correct |
19 |
Correct |
65 ms |
2384 KB |
Output is correct |
20 |
Correct |
76 ms |
2412 KB |
Output is correct |
21 |
Correct |
47 ms |
2392 KB |
Output is correct |
22 |
Correct |
28 ms |
1884 KB |
Output is correct |
23 |
Correct |
11 ms |
1628 KB |
Output is correct |
24 |
Correct |
47 ms |
2224 KB |
Output is correct |
25 |
Correct |
49 ms |
2384 KB |
Output is correct |
26 |
Correct |
81 ms |
2384 KB |
Output is correct |
27 |
Correct |
51 ms |
2328 KB |
Output is correct |
28 |
Correct |
51 ms |
2388 KB |
Output is correct |
29 |
Correct |
76 ms |
2388 KB |
Output is correct |
30 |
Correct |
73 ms |
2388 KB |
Output is correct |
31 |
Runtime error |
1 ms |
600 KB |
Execution killed with signal 11 |
32 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
604 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
604 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
44 ms |
2388 KB |
Output is correct |
17 |
Correct |
44 ms |
2392 KB |
Output is correct |
18 |
Correct |
54 ms |
2364 KB |
Output is correct |
19 |
Correct |
65 ms |
2384 KB |
Output is correct |
20 |
Correct |
76 ms |
2412 KB |
Output is correct |
21 |
Correct |
47 ms |
2392 KB |
Output is correct |
22 |
Correct |
28 ms |
1884 KB |
Output is correct |
23 |
Correct |
11 ms |
1628 KB |
Output is correct |
24 |
Correct |
47 ms |
2224 KB |
Output is correct |
25 |
Correct |
49 ms |
2384 KB |
Output is correct |
26 |
Correct |
81 ms |
2384 KB |
Output is correct |
27 |
Correct |
51 ms |
2328 KB |
Output is correct |
28 |
Correct |
51 ms |
2388 KB |
Output is correct |
29 |
Correct |
76 ms |
2388 KB |
Output is correct |
30 |
Correct |
73 ms |
2388 KB |
Output is correct |
31 |
Runtime error |
1 ms |
600 KB |
Execution killed with signal 11 |
32 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
604 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
604 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
44 ms |
2388 KB |
Output is correct |
17 |
Correct |
44 ms |
2392 KB |
Output is correct |
18 |
Correct |
54 ms |
2364 KB |
Output is correct |
19 |
Correct |
65 ms |
2384 KB |
Output is correct |
20 |
Correct |
76 ms |
2412 KB |
Output is correct |
21 |
Correct |
47 ms |
2392 KB |
Output is correct |
22 |
Correct |
28 ms |
1884 KB |
Output is correct |
23 |
Correct |
11 ms |
1628 KB |
Output is correct |
24 |
Correct |
47 ms |
2224 KB |
Output is correct |
25 |
Correct |
49 ms |
2384 KB |
Output is correct |
26 |
Correct |
81 ms |
2384 KB |
Output is correct |
27 |
Correct |
51 ms |
2328 KB |
Output is correct |
28 |
Correct |
51 ms |
2388 KB |
Output is correct |
29 |
Correct |
76 ms |
2388 KB |
Output is correct |
30 |
Correct |
73 ms |
2388 KB |
Output is correct |
31 |
Runtime error |
1 ms |
600 KB |
Execution killed with signal 11 |
32 |
Halted |
0 ms |
0 KB |
- |