#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<long long, long long> pll;
typedef pair<int,int> pii;
typedef vector<long long> vl;
typedef vector<int> vi;
ll dp[511][511];
int main(){
int n;
cin>>n;
vl arr(n+1);
for(int i = 1; i <= n; i++) cin>>arr[i];
ll pref[n+1];
for(int i = 1; i <= n; i++) pref[i] = pref[i-1] + arr[i];
memset(dp, 0x3f, sizeof dp);
dp[0][0] = 0;
for(int i = 1; i <= n; i++){
for(int j = 1; j <= i; j++){
for(int k = i; k >= 1; k--){
ll sum = pref[i] - pref[k-1];
if(sum >= dp[k-1][j-1]){
dp[i][j] = min(dp[i][j], sum);
}
}
}
}
int ans = 0;
for(int i = 1; i <= n; i++){
if(dp[n][i] < 1e18 + 5) ans = max(ans, i);
}
cout<<ans<<endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2304 KB |
Output is correct |
2 |
Correct |
2 ms |
2260 KB |
Output is correct |
3 |
Correct |
2 ms |
2260 KB |
Output is correct |
4 |
Correct |
1 ms |
2260 KB |
Output is correct |
5 |
Correct |
1 ms |
2260 KB |
Output is correct |
6 |
Correct |
1 ms |
2260 KB |
Output is correct |
7 |
Correct |
1 ms |
2260 KB |
Output is correct |
8 |
Correct |
1 ms |
2260 KB |
Output is correct |
9 |
Correct |
2 ms |
2224 KB |
Output is correct |
10 |
Correct |
1 ms |
2260 KB |
Output is correct |
11 |
Correct |
1 ms |
2260 KB |
Output is correct |
12 |
Correct |
1 ms |
2260 KB |
Output is correct |
13 |
Correct |
1 ms |
2260 KB |
Output is correct |
14 |
Correct |
1 ms |
2260 KB |
Output is correct |
15 |
Correct |
1 ms |
2260 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2304 KB |
Output is correct |
2 |
Correct |
2 ms |
2260 KB |
Output is correct |
3 |
Correct |
2 ms |
2260 KB |
Output is correct |
4 |
Correct |
1 ms |
2260 KB |
Output is correct |
5 |
Correct |
1 ms |
2260 KB |
Output is correct |
6 |
Correct |
1 ms |
2260 KB |
Output is correct |
7 |
Correct |
1 ms |
2260 KB |
Output is correct |
8 |
Correct |
1 ms |
2260 KB |
Output is correct |
9 |
Correct |
2 ms |
2224 KB |
Output is correct |
10 |
Correct |
1 ms |
2260 KB |
Output is correct |
11 |
Correct |
1 ms |
2260 KB |
Output is correct |
12 |
Correct |
1 ms |
2260 KB |
Output is correct |
13 |
Correct |
1 ms |
2260 KB |
Output is correct |
14 |
Correct |
1 ms |
2260 KB |
Output is correct |
15 |
Correct |
1 ms |
2260 KB |
Output is correct |
16 |
Correct |
43 ms |
2332 KB |
Output is correct |
17 |
Correct |
42 ms |
2332 KB |
Output is correct |
18 |
Correct |
48 ms |
2260 KB |
Output is correct |
19 |
Correct |
68 ms |
2328 KB |
Output is correct |
20 |
Correct |
85 ms |
2340 KB |
Output is correct |
21 |
Correct |
45 ms |
2332 KB |
Output is correct |
22 |
Correct |
32 ms |
2260 KB |
Output is correct |
23 |
Correct |
18 ms |
2344 KB |
Output is correct |
24 |
Correct |
47 ms |
2340 KB |
Output is correct |
25 |
Correct |
45 ms |
2260 KB |
Output is correct |
26 |
Correct |
85 ms |
2328 KB |
Output is correct |
27 |
Correct |
52 ms |
2324 KB |
Output is correct |
28 |
Correct |
51 ms |
2260 KB |
Output is correct |
29 |
Correct |
85 ms |
2260 KB |
Output is correct |
30 |
Correct |
82 ms |
2328 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2304 KB |
Output is correct |
2 |
Correct |
2 ms |
2260 KB |
Output is correct |
3 |
Correct |
2 ms |
2260 KB |
Output is correct |
4 |
Correct |
1 ms |
2260 KB |
Output is correct |
5 |
Correct |
1 ms |
2260 KB |
Output is correct |
6 |
Correct |
1 ms |
2260 KB |
Output is correct |
7 |
Correct |
1 ms |
2260 KB |
Output is correct |
8 |
Correct |
1 ms |
2260 KB |
Output is correct |
9 |
Correct |
2 ms |
2224 KB |
Output is correct |
10 |
Correct |
1 ms |
2260 KB |
Output is correct |
11 |
Correct |
1 ms |
2260 KB |
Output is correct |
12 |
Correct |
1 ms |
2260 KB |
Output is correct |
13 |
Correct |
1 ms |
2260 KB |
Output is correct |
14 |
Correct |
1 ms |
2260 KB |
Output is correct |
15 |
Correct |
1 ms |
2260 KB |
Output is correct |
16 |
Correct |
43 ms |
2332 KB |
Output is correct |
17 |
Correct |
42 ms |
2332 KB |
Output is correct |
18 |
Correct |
48 ms |
2260 KB |
Output is correct |
19 |
Correct |
68 ms |
2328 KB |
Output is correct |
20 |
Correct |
85 ms |
2340 KB |
Output is correct |
21 |
Correct |
45 ms |
2332 KB |
Output is correct |
22 |
Correct |
32 ms |
2260 KB |
Output is correct |
23 |
Correct |
18 ms |
2344 KB |
Output is correct |
24 |
Correct |
47 ms |
2340 KB |
Output is correct |
25 |
Correct |
45 ms |
2260 KB |
Output is correct |
26 |
Correct |
85 ms |
2328 KB |
Output is correct |
27 |
Correct |
52 ms |
2324 KB |
Output is correct |
28 |
Correct |
51 ms |
2260 KB |
Output is correct |
29 |
Correct |
85 ms |
2260 KB |
Output is correct |
30 |
Correct |
82 ms |
2328 KB |
Output is correct |
31 |
Runtime error |
49 ms |
4556 KB |
Execution killed with signal 11 |
32 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2304 KB |
Output is correct |
2 |
Correct |
2 ms |
2260 KB |
Output is correct |
3 |
Correct |
2 ms |
2260 KB |
Output is correct |
4 |
Correct |
1 ms |
2260 KB |
Output is correct |
5 |
Correct |
1 ms |
2260 KB |
Output is correct |
6 |
Correct |
1 ms |
2260 KB |
Output is correct |
7 |
Correct |
1 ms |
2260 KB |
Output is correct |
8 |
Correct |
1 ms |
2260 KB |
Output is correct |
9 |
Correct |
2 ms |
2224 KB |
Output is correct |
10 |
Correct |
1 ms |
2260 KB |
Output is correct |
11 |
Correct |
1 ms |
2260 KB |
Output is correct |
12 |
Correct |
1 ms |
2260 KB |
Output is correct |
13 |
Correct |
1 ms |
2260 KB |
Output is correct |
14 |
Correct |
1 ms |
2260 KB |
Output is correct |
15 |
Correct |
1 ms |
2260 KB |
Output is correct |
16 |
Correct |
43 ms |
2332 KB |
Output is correct |
17 |
Correct |
42 ms |
2332 KB |
Output is correct |
18 |
Correct |
48 ms |
2260 KB |
Output is correct |
19 |
Correct |
68 ms |
2328 KB |
Output is correct |
20 |
Correct |
85 ms |
2340 KB |
Output is correct |
21 |
Correct |
45 ms |
2332 KB |
Output is correct |
22 |
Correct |
32 ms |
2260 KB |
Output is correct |
23 |
Correct |
18 ms |
2344 KB |
Output is correct |
24 |
Correct |
47 ms |
2340 KB |
Output is correct |
25 |
Correct |
45 ms |
2260 KB |
Output is correct |
26 |
Correct |
85 ms |
2328 KB |
Output is correct |
27 |
Correct |
52 ms |
2324 KB |
Output is correct |
28 |
Correct |
51 ms |
2260 KB |
Output is correct |
29 |
Correct |
85 ms |
2260 KB |
Output is correct |
30 |
Correct |
82 ms |
2328 KB |
Output is correct |
31 |
Runtime error |
49 ms |
4556 KB |
Execution killed with signal 11 |
32 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2304 KB |
Output is correct |
2 |
Correct |
2 ms |
2260 KB |
Output is correct |
3 |
Correct |
2 ms |
2260 KB |
Output is correct |
4 |
Correct |
1 ms |
2260 KB |
Output is correct |
5 |
Correct |
1 ms |
2260 KB |
Output is correct |
6 |
Correct |
1 ms |
2260 KB |
Output is correct |
7 |
Correct |
1 ms |
2260 KB |
Output is correct |
8 |
Correct |
1 ms |
2260 KB |
Output is correct |
9 |
Correct |
2 ms |
2224 KB |
Output is correct |
10 |
Correct |
1 ms |
2260 KB |
Output is correct |
11 |
Correct |
1 ms |
2260 KB |
Output is correct |
12 |
Correct |
1 ms |
2260 KB |
Output is correct |
13 |
Correct |
1 ms |
2260 KB |
Output is correct |
14 |
Correct |
1 ms |
2260 KB |
Output is correct |
15 |
Correct |
1 ms |
2260 KB |
Output is correct |
16 |
Correct |
43 ms |
2332 KB |
Output is correct |
17 |
Correct |
42 ms |
2332 KB |
Output is correct |
18 |
Correct |
48 ms |
2260 KB |
Output is correct |
19 |
Correct |
68 ms |
2328 KB |
Output is correct |
20 |
Correct |
85 ms |
2340 KB |
Output is correct |
21 |
Correct |
45 ms |
2332 KB |
Output is correct |
22 |
Correct |
32 ms |
2260 KB |
Output is correct |
23 |
Correct |
18 ms |
2344 KB |
Output is correct |
24 |
Correct |
47 ms |
2340 KB |
Output is correct |
25 |
Correct |
45 ms |
2260 KB |
Output is correct |
26 |
Correct |
85 ms |
2328 KB |
Output is correct |
27 |
Correct |
52 ms |
2324 KB |
Output is correct |
28 |
Correct |
51 ms |
2260 KB |
Output is correct |
29 |
Correct |
85 ms |
2260 KB |
Output is correct |
30 |
Correct |
82 ms |
2328 KB |
Output is correct |
31 |
Runtime error |
49 ms |
4556 KB |
Execution killed with signal 11 |
32 |
Halted |
0 ms |
0 KB |
- |