#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define pb push_back
#define ff first
#define sc second
#define int ll
signed main() {
#ifdef LOCAL
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
int n; cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) cin >> a[i];
vector<int> pref(n + 1, 0);
for (int i = 1; i <= n; i++) pref[i] = pref[i - 1] + a[i - 1];
vector<vector<int>> dp(n + 1, vector<int>(n + 1, -1e9));
dp[0][0] = 0;
for (int i = 1; i <= n; i++) {
for (int len = 1; len <= i; len++) {
int cs = pref[i] - pref[i - len];
for (int len2 = 0; len2 <= i - len; len2++) {
if (cs >= pref[i - len] - pref[i - len - len2]) dp[i][len] = max(dp[i][len], 1 + dp[i - len][len2]);
}
//cout << i << ' ' << len << ' ' << dp[i][len] << '\n';
}
}
int mx = 0;
for (int i = 0; i <= n; i++) mx = max(mx, dp[n][i]);
cout << mx << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 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 |
1 ms |
344 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 |
436 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 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 |
1 ms |
344 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 |
436 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 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 |
23 ms |
2396 KB |
Output is correct |
17 |
Correct |
23 ms |
2396 KB |
Output is correct |
18 |
Correct |
22 ms |
2396 KB |
Output is correct |
19 |
Correct |
22 ms |
2432 KB |
Output is correct |
20 |
Correct |
27 ms |
2652 KB |
Output is correct |
21 |
Correct |
23 ms |
2428 KB |
Output is correct |
22 |
Correct |
12 ms |
1716 KB |
Output is correct |
23 |
Correct |
6 ms |
1164 KB |
Output is correct |
24 |
Correct |
22 ms |
2392 KB |
Output is correct |
25 |
Correct |
22 ms |
2396 KB |
Output is correct |
26 |
Correct |
23 ms |
2396 KB |
Output is correct |
27 |
Correct |
21 ms |
2396 KB |
Output is correct |
28 |
Correct |
23 ms |
2648 KB |
Output is correct |
29 |
Correct |
23 ms |
2428 KB |
Output is correct |
30 |
Correct |
25 ms |
2424 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 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 |
1 ms |
344 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 |
436 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 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 |
23 ms |
2396 KB |
Output is correct |
17 |
Correct |
23 ms |
2396 KB |
Output is correct |
18 |
Correct |
22 ms |
2396 KB |
Output is correct |
19 |
Correct |
22 ms |
2432 KB |
Output is correct |
20 |
Correct |
27 ms |
2652 KB |
Output is correct |
21 |
Correct |
23 ms |
2428 KB |
Output is correct |
22 |
Correct |
12 ms |
1716 KB |
Output is correct |
23 |
Correct |
6 ms |
1164 KB |
Output is correct |
24 |
Correct |
22 ms |
2392 KB |
Output is correct |
25 |
Correct |
22 ms |
2396 KB |
Output is correct |
26 |
Correct |
23 ms |
2396 KB |
Output is correct |
27 |
Correct |
21 ms |
2396 KB |
Output is correct |
28 |
Correct |
23 ms |
2648 KB |
Output is correct |
29 |
Correct |
23 ms |
2428 KB |
Output is correct |
30 |
Correct |
25 ms |
2424 KB |
Output is correct |
31 |
Execution timed out |
1554 ms |
71004 KB |
Time limit exceeded |
32 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 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 |
1 ms |
344 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 |
436 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 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 |
23 ms |
2396 KB |
Output is correct |
17 |
Correct |
23 ms |
2396 KB |
Output is correct |
18 |
Correct |
22 ms |
2396 KB |
Output is correct |
19 |
Correct |
22 ms |
2432 KB |
Output is correct |
20 |
Correct |
27 ms |
2652 KB |
Output is correct |
21 |
Correct |
23 ms |
2428 KB |
Output is correct |
22 |
Correct |
12 ms |
1716 KB |
Output is correct |
23 |
Correct |
6 ms |
1164 KB |
Output is correct |
24 |
Correct |
22 ms |
2392 KB |
Output is correct |
25 |
Correct |
22 ms |
2396 KB |
Output is correct |
26 |
Correct |
23 ms |
2396 KB |
Output is correct |
27 |
Correct |
21 ms |
2396 KB |
Output is correct |
28 |
Correct |
23 ms |
2648 KB |
Output is correct |
29 |
Correct |
23 ms |
2428 KB |
Output is correct |
30 |
Correct |
25 ms |
2424 KB |
Output is correct |
31 |
Execution timed out |
1554 ms |
71004 KB |
Time limit exceeded |
32 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 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 |
1 ms |
344 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 |
436 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 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 |
23 ms |
2396 KB |
Output is correct |
17 |
Correct |
23 ms |
2396 KB |
Output is correct |
18 |
Correct |
22 ms |
2396 KB |
Output is correct |
19 |
Correct |
22 ms |
2432 KB |
Output is correct |
20 |
Correct |
27 ms |
2652 KB |
Output is correct |
21 |
Correct |
23 ms |
2428 KB |
Output is correct |
22 |
Correct |
12 ms |
1716 KB |
Output is correct |
23 |
Correct |
6 ms |
1164 KB |
Output is correct |
24 |
Correct |
22 ms |
2392 KB |
Output is correct |
25 |
Correct |
22 ms |
2396 KB |
Output is correct |
26 |
Correct |
23 ms |
2396 KB |
Output is correct |
27 |
Correct |
21 ms |
2396 KB |
Output is correct |
28 |
Correct |
23 ms |
2648 KB |
Output is correct |
29 |
Correct |
23 ms |
2428 KB |
Output is correct |
30 |
Correct |
25 ms |
2424 KB |
Output is correct |
31 |
Execution timed out |
1554 ms |
71004 KB |
Time limit exceeded |
32 |
Halted |
0 ms |
0 KB |
- |