#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//#include "interactive.h"
#define pb push_back
#define F first
#define S second
#define ll long long
#define ld long double
#define sqr(x) (x) * (x)
//#define all(a) a.begin(), a.end()
using namespace std;
const int maxn = 3005;
const ll inf = 1e18;
ll dp[maxn][maxn];
int a[maxn];
ll sum[maxn];
ll f(int l, int r)
{
return sum[r] - (l > 0 ? sum[l - 1] : 0);
}
int main()
{
#ifdef LOCAL
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif // LOCAL
// ios_base::sync_with_stdio(0);
// cin.tie(0);
// cout.tie(0);
int n;
cin >> n;
for(int i = 0; i < n; ++i)
{
cin >> a[i];
sum[i] = a[i] + (i > 0 ? sum[i - 1] : 0);
}
for(int i = 0; i < n; ++i)
for(int j = 0; j <= i + 1; ++j)
dp[i][j] = inf;
dp[0][1] = a[1];
for(int i = 0; i < n - 1; ++i)
for(int j = 0; j <= i + 1; ++j)
{
if (dp[i][j] == inf) continue;
dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + a[i + 1]);
{
int l = i + 1, r = n;
int b = n + 1;
while(l <= r)
{
int m = (l + r) / 2;
if (f(i + 1, m) >= dp[i][j])
{
b = min(b, m);
r = m - 1;
}
else
{
l = m + 1;
}
}
if (b < n + 1)
{
dp[b][j + 1] = min(dp[b][j + 1], f(i + 1, b));
}
}
}
int ans = 0;
for(int j = 1; j <= n; ++j)
if (dp[n - 1][j] != inf) ans = j;
cout << ans << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |