#include "bits/stdc++.h"
#include <chrono>
#include <thread>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define intt long long
#define int intt
#define pb push_back
#define endl '\n'
#define F first
#define S second
#define pii pair<int,int>
#define pll pair<intt,intt>
#define ld long double
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(x) x.begin(), x.end()
using namespace std;
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int sz = 2e6+5;
const int sz1 = 505;
const int mod = 998244353;
const int inf = 2e9+7;
const intt infl = 1e18;
const ld eps = 1e-9;
int a[sz];
int dp[sz1][sz1];
int pref[sz];
intt i,j;
void solve(){
int n;
cin >> n;
for ( i = 1; i <= n; i++ ){
cin >> a[i];
pref[i] = pref[i-1]+a[i];
}
for ( int r = 1; r <= n; r++ ){
dp[0][r] = 1;
for ( int l = 1; l < r; l++ ){
for ( int i = 0; i < l; i++ ){
if ( pref[r]-pref[l] >= pref[l]-pref[i] ){
dp[l][r] = max(dp[l][r], dp[i][l]+1);
}
}
}
}
int res = 1;
for ( i = 1; i <= n; i++ ) res = max(res, dp[i][n]);
cout << res << endl;
}
signed main(){
fastio;
int t = 1;
// cin >> t;
for ( int cs = 1; cs <= t; cs++ ) {
// cout << "Case " << cs << ": ";
solve();
}
// while ( cin >> n and n ){
// cin >> m;
// solve();
// }
}
// 4 15 8 23 42 16
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |