#include <bits/stdc++.h>
#include <math.h>
#pragma GCC target("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
#define SPEED ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define str string
#define pb push_back
#define pf push_front
#define nl "\n"
#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define ff first
#define ss second
#define len(a) a.size()
#define sz(v) (int)(v.size())
#define pii pair<int,int>
const int N = 5e5 + 1;
const int md = 998244353;
const int mod = 1e9 + 7;
const int mega = 1e6 + 3;
const int inf = 1e9;
int n , a[N + 1] , dp[505][505] , pref[N];
void solve(){
cin >> n;
for(int i = 1; i <= n; ++i)cin >> a[i] , pref[i] = pref[i - 1] + a[i];
for(int i = 1; i <= n; ++i){
for(int j = 1; j <= n; ++j){
dp[i][j] = -inf;
}
}
for(int i = 1; i <= n; ++ i) dp[1][i] = 1;
for(int i = 1; i <= n; ++i){
for(int j = i; j >= 1; j--){
for(int k = j - 1; k >= 1; k--){
int sum1 = pref[i] - pref[j - 1];
int sum2 = pref[j - 1] - pref[k - 1];
if(sum2 <= sum1){
dp[j][i] = max(dp[j][i] , dp[k][j - 1] + 1);
}
}
}
}
int ans = 0;
for(int i = 1; i <= n; ++i)ans = max(dp[i][n] , ans);
cout << ans << nl;
}
signed main(){
SPEED;
int t = 1;
//cin >> t;
while (t--) {
solve();
}
#ifndef ONLINE_JUDGE
cerr << "\n" << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4696 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4440 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4696 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4440 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
30 ms |
4444 KB |
Output is correct |
17 |
Correct |
45 ms |
4444 KB |
Output is correct |
18 |
Correct |
43 ms |
4440 KB |
Output is correct |
19 |
Correct |
27 ms |
4444 KB |
Output is correct |
20 |
Correct |
30 ms |
4444 KB |
Output is correct |
21 |
Correct |
44 ms |
4444 KB |
Output is correct |
22 |
Correct |
23 ms |
4444 KB |
Output is correct |
23 |
Correct |
10 ms |
4576 KB |
Output is correct |
24 |
Correct |
43 ms |
4444 KB |
Output is correct |
25 |
Correct |
44 ms |
4444 KB |
Output is correct |
26 |
Correct |
34 ms |
4440 KB |
Output is correct |
27 |
Correct |
25 ms |
4444 KB |
Output is correct |
28 |
Correct |
48 ms |
4444 KB |
Output is correct |
29 |
Correct |
33 ms |
4548 KB |
Output is correct |
30 |
Correct |
29 ms |
4440 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4696 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4440 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
30 ms |
4444 KB |
Output is correct |
17 |
Correct |
45 ms |
4444 KB |
Output is correct |
18 |
Correct |
43 ms |
4440 KB |
Output is correct |
19 |
Correct |
27 ms |
4444 KB |
Output is correct |
20 |
Correct |
30 ms |
4444 KB |
Output is correct |
21 |
Correct |
44 ms |
4444 KB |
Output is correct |
22 |
Correct |
23 ms |
4444 KB |
Output is correct |
23 |
Correct |
10 ms |
4576 KB |
Output is correct |
24 |
Correct |
43 ms |
4444 KB |
Output is correct |
25 |
Correct |
44 ms |
4444 KB |
Output is correct |
26 |
Correct |
34 ms |
4440 KB |
Output is correct |
27 |
Correct |
25 ms |
4444 KB |
Output is correct |
28 |
Correct |
48 ms |
4444 KB |
Output is correct |
29 |
Correct |
33 ms |
4548 KB |
Output is correct |
30 |
Correct |
29 ms |
4440 KB |
Output is correct |
31 |
Runtime error |
11 ms |
15836 KB |
Execution killed with signal 11 |
32 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4696 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4440 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
30 ms |
4444 KB |
Output is correct |
17 |
Correct |
45 ms |
4444 KB |
Output is correct |
18 |
Correct |
43 ms |
4440 KB |
Output is correct |
19 |
Correct |
27 ms |
4444 KB |
Output is correct |
20 |
Correct |
30 ms |
4444 KB |
Output is correct |
21 |
Correct |
44 ms |
4444 KB |
Output is correct |
22 |
Correct |
23 ms |
4444 KB |
Output is correct |
23 |
Correct |
10 ms |
4576 KB |
Output is correct |
24 |
Correct |
43 ms |
4444 KB |
Output is correct |
25 |
Correct |
44 ms |
4444 KB |
Output is correct |
26 |
Correct |
34 ms |
4440 KB |
Output is correct |
27 |
Correct |
25 ms |
4444 KB |
Output is correct |
28 |
Correct |
48 ms |
4444 KB |
Output is correct |
29 |
Correct |
33 ms |
4548 KB |
Output is correct |
30 |
Correct |
29 ms |
4440 KB |
Output is correct |
31 |
Runtime error |
11 ms |
15836 KB |
Execution killed with signal 11 |
32 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4696 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4440 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
30 ms |
4444 KB |
Output is correct |
17 |
Correct |
45 ms |
4444 KB |
Output is correct |
18 |
Correct |
43 ms |
4440 KB |
Output is correct |
19 |
Correct |
27 ms |
4444 KB |
Output is correct |
20 |
Correct |
30 ms |
4444 KB |
Output is correct |
21 |
Correct |
44 ms |
4444 KB |
Output is correct |
22 |
Correct |
23 ms |
4444 KB |
Output is correct |
23 |
Correct |
10 ms |
4576 KB |
Output is correct |
24 |
Correct |
43 ms |
4444 KB |
Output is correct |
25 |
Correct |
44 ms |
4444 KB |
Output is correct |
26 |
Correct |
34 ms |
4440 KB |
Output is correct |
27 |
Correct |
25 ms |
4444 KB |
Output is correct |
28 |
Correct |
48 ms |
4444 KB |
Output is correct |
29 |
Correct |
33 ms |
4548 KB |
Output is correct |
30 |
Correct |
29 ms |
4440 KB |
Output is correct |
31 |
Runtime error |
11 ms |
15836 KB |
Execution killed with signal 11 |
32 |
Halted |
0 ms |
0 KB |
- |