This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main()
{
int n; cin >> n;
vector<int> a(n + 1), pref(n + 1);
for (int i = 1; i<= n; i++){
cin >> a[i];
pref[i] = pref[i - 1] + a[i];
}
vector<vector<int>> dp(n + 1, vector<int> (n + 1, -1));
for (int i = 0; i <= n; i++) dp[i][0] = 0;
for (int i = 1; i <= n; i++){
for (int j = 0; j < i; j++){
int ini = 0, fin = i;
while(ini < fin){
int m = (ini + fin) / 2;
if (dp[m][j] >= 0 && pref[i] >= dp[m][j] + pref[m]){
fin = m;
}else ini = m + 1;
}
int suma = pref[i] - pref[ini];
if (suma >= dp[ini][j] && dp[ini][j] >= 0){
if (dp[i][j + 1] == -1) dp[i][j + 1] = suma;
else dp[i][j + 1] = min(suma, dp[i][j + 1]);
}else{
dp[i][j + 1] = dp[i - 1][j + 1];
}
}
}
/*for (int i = 0; i <= n; i++){
for (int j = 0; j <= n; j++){
cout << dp[i][j] << ' ';
}
cout << endl;
}*/
int ans = 0;
for (int i = 1; i <= n; i++){
if (dp[n][i] != -1) ans = max(ans, i);
}
cout << ans << endl;
}
# | 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... |