#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x).size()
#define S second
#define F first
#define all(x) (x).begin(), (x).end()
using namespace std;
const bool dbg_flg = 1;
#define debug(x) if (dbg_flg) cerr << #x << ' ' << x << '\n'
#define debug_pair(x) if (dbg_flg) cerr << #x << ' ' << x.F << ' ' << x.S << '\n'
const int inf = 1e9 + 7;
const int MAXN = 3000 + 5;
int n;
ll a[MAXN];
ll pref[MAXN];
ll dp[MAXN][MAXN];
int main() {
//~ freopen(".in", "r", stdin);
//~ freopen(".out", "w", stdout);
ios_base::sync_with_stdio(NULL);
cin.tie(NULL);
cout.tie(NULL);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
pref[i] = pref[i - 1] + a[i];
}
for (int i = 0; i <= n; ++i) {
for (int j = 0; j <= n; ++j) {
dp[i][j] = (ll)1e18;
}
}
dp[0][0] = 0;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= i; ++j) {
for (int L = 1; L <= i; ++L) {
if (dp[L - 1][j - 1] <= pref[i] - pref[L - 1]) {
dp[i][j] = min(dp[i][j], pref[i] - pref[L - 1]);
}
}
}
}
ll ans = 0;
while (ans < n && dp[n][ans + 1] != (ll)1e18) {
++ans;
}
printf("%lld\n", ans);
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
4 ms |
504 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
1 ms |
376 KB |
Output is correct |
5 |
Correct |
6 ms |
504 KB |
Output is correct |
6 |
Correct |
2 ms |
504 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
3 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
504 KB |
Output is correct |
14 |
Correct |
2 ms |
504 KB |
Output is correct |
15 |
Correct |
2 ms |
420 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
4 ms |
504 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
1 ms |
376 KB |
Output is correct |
5 |
Correct |
6 ms |
504 KB |
Output is correct |
6 |
Correct |
2 ms |
504 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
3 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
504 KB |
Output is correct |
14 |
Correct |
2 ms |
504 KB |
Output is correct |
15 |
Correct |
2 ms |
420 KB |
Output is correct |
16 |
Correct |
81 ms |
4472 KB |
Output is correct |
17 |
Correct |
70 ms |
4344 KB |
Output is correct |
18 |
Correct |
74 ms |
4344 KB |
Output is correct |
19 |
Correct |
93 ms |
4472 KB |
Output is correct |
20 |
Correct |
105 ms |
4344 KB |
Output is correct |
21 |
Correct |
75 ms |
4344 KB |
Output is correct |
22 |
Correct |
39 ms |
3192 KB |
Output is correct |
23 |
Correct |
18 ms |
2296 KB |
Output is correct |
24 |
Correct |
75 ms |
4344 KB |
Output is correct |
25 |
Correct |
74 ms |
4428 KB |
Output is correct |
26 |
Correct |
104 ms |
4344 KB |
Output is correct |
27 |
Correct |
80 ms |
4348 KB |
Output is correct |
28 |
Correct |
75 ms |
4344 KB |
Output is correct |
29 |
Correct |
106 ms |
4472 KB |
Output is correct |
30 |
Correct |
104 ms |
4380 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
4 ms |
504 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
1 ms |
376 KB |
Output is correct |
5 |
Correct |
6 ms |
504 KB |
Output is correct |
6 |
Correct |
2 ms |
504 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
3 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
504 KB |
Output is correct |
14 |
Correct |
2 ms |
504 KB |
Output is correct |
15 |
Correct |
2 ms |
420 KB |
Output is correct |
16 |
Correct |
81 ms |
4472 KB |
Output is correct |
17 |
Correct |
70 ms |
4344 KB |
Output is correct |
18 |
Correct |
74 ms |
4344 KB |
Output is correct |
19 |
Correct |
93 ms |
4472 KB |
Output is correct |
20 |
Correct |
105 ms |
4344 KB |
Output is correct |
21 |
Correct |
75 ms |
4344 KB |
Output is correct |
22 |
Correct |
39 ms |
3192 KB |
Output is correct |
23 |
Correct |
18 ms |
2296 KB |
Output is correct |
24 |
Correct |
75 ms |
4344 KB |
Output is correct |
25 |
Correct |
74 ms |
4428 KB |
Output is correct |
26 |
Correct |
104 ms |
4344 KB |
Output is correct |
27 |
Correct |
80 ms |
4348 KB |
Output is correct |
28 |
Correct |
75 ms |
4344 KB |
Output is correct |
29 |
Correct |
106 ms |
4472 KB |
Output is correct |
30 |
Correct |
104 ms |
4380 KB |
Output is correct |
31 |
Execution timed out |
1547 ms |
71032 KB |
Time limit exceeded |
32 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
4 ms |
504 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
1 ms |
376 KB |
Output is correct |
5 |
Correct |
6 ms |
504 KB |
Output is correct |
6 |
Correct |
2 ms |
504 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
3 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
504 KB |
Output is correct |
14 |
Correct |
2 ms |
504 KB |
Output is correct |
15 |
Correct |
2 ms |
420 KB |
Output is correct |
16 |
Correct |
81 ms |
4472 KB |
Output is correct |
17 |
Correct |
70 ms |
4344 KB |
Output is correct |
18 |
Correct |
74 ms |
4344 KB |
Output is correct |
19 |
Correct |
93 ms |
4472 KB |
Output is correct |
20 |
Correct |
105 ms |
4344 KB |
Output is correct |
21 |
Correct |
75 ms |
4344 KB |
Output is correct |
22 |
Correct |
39 ms |
3192 KB |
Output is correct |
23 |
Correct |
18 ms |
2296 KB |
Output is correct |
24 |
Correct |
75 ms |
4344 KB |
Output is correct |
25 |
Correct |
74 ms |
4428 KB |
Output is correct |
26 |
Correct |
104 ms |
4344 KB |
Output is correct |
27 |
Correct |
80 ms |
4348 KB |
Output is correct |
28 |
Correct |
75 ms |
4344 KB |
Output is correct |
29 |
Correct |
106 ms |
4472 KB |
Output is correct |
30 |
Correct |
104 ms |
4380 KB |
Output is correct |
31 |
Execution timed out |
1547 ms |
71032 KB |
Time limit exceeded |
32 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
4 ms |
504 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
1 ms |
376 KB |
Output is correct |
5 |
Correct |
6 ms |
504 KB |
Output is correct |
6 |
Correct |
2 ms |
504 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
3 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
504 KB |
Output is correct |
14 |
Correct |
2 ms |
504 KB |
Output is correct |
15 |
Correct |
2 ms |
420 KB |
Output is correct |
16 |
Correct |
81 ms |
4472 KB |
Output is correct |
17 |
Correct |
70 ms |
4344 KB |
Output is correct |
18 |
Correct |
74 ms |
4344 KB |
Output is correct |
19 |
Correct |
93 ms |
4472 KB |
Output is correct |
20 |
Correct |
105 ms |
4344 KB |
Output is correct |
21 |
Correct |
75 ms |
4344 KB |
Output is correct |
22 |
Correct |
39 ms |
3192 KB |
Output is correct |
23 |
Correct |
18 ms |
2296 KB |
Output is correct |
24 |
Correct |
75 ms |
4344 KB |
Output is correct |
25 |
Correct |
74 ms |
4428 KB |
Output is correct |
26 |
Correct |
104 ms |
4344 KB |
Output is correct |
27 |
Correct |
80 ms |
4348 KB |
Output is correct |
28 |
Correct |
75 ms |
4344 KB |
Output is correct |
29 |
Correct |
106 ms |
4472 KB |
Output is correct |
30 |
Correct |
104 ms |
4380 KB |
Output is correct |
31 |
Execution timed out |
1547 ms |
71032 KB |
Time limit exceeded |
32 |
Halted |
0 ms |
0 KB |
- |