#include <bits/stdc++.h>
using namespace std;
#define int long long
#define inf 0x3F3F3F3F3F3F3F3F
const int MXN = 2e3 + 5;
const int mod = 1e9 + 7;
int dp[MXN][MXN];
void _()
{
int n;
cin >> n;
int a[n], p[n];
for (int &i : a) cin >> i;
for (int i = 0; i < n; i++) p[i] = (i ? p[i - 1] : 0) + a[i];
auto sum = [&](int l, int r)
{
if (l > r) return 0LL;
return p[r] - (l ? p[l - 1] : 0LL);
};
for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) dp[i][j] = -inf;
for (int i = 0; i < n; i++) dp[0][i] = 1;
int res = 1;
for (int i = 1; i < n; i++)
{
for (int j = 1; j < n; j++)
{
for (int k = 0; k < j; k++)
{
if (sum(k, j - 1) <= sum(j, i))
{
dp[j][i] = max(dp[j][i], dp[k][j - 1] + 1);
}
}
res = max(res, dp[j][i]);
}
}
cout << res << '\n';
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int t = 1;
// cin >> t;
while (t--) _();
}
# | 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... |