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;
int main(){
int n; cin >> n;
vector<int> tam(n+1, 0);
vector<int> sum(n+1, 0);
for(int i=1; i<=n; i++) cin >> tam[i];
for(int i=1; i<=n; i++) sum[i] = sum[i-1] + tam[i];
vector<vector<int>> dp(n+1, vector<int> (n+1,0));
int maior = 0;
for(int l = 1; l<= n; l++) for(int r = l; r<=n; r++){
int somaPedaco = sum[r-1] - sum[l-1];
if(somaPedaco >= sum[l-1]) continue;
int qnt = 0;
int cima = l, baixo = l-1;
int SumCima = tam[l];
int SumBaixo = tam[l-1];
while(cima < r){
if(SumCima == SumBaixo) {
qnt++;
baixo--;
cima++;
SumBaixo+= tam[baixo];
SumCima+= tam[cima];
dp[l][r] = min(dp[l][r], dp[min(1, baixo)][l-1] + qnt);
}
else if(SumCima > SumBaixo) {baixo--; SumBaixo+= tam[baixo]; dp[l][r] = min(dp[l][r], dp[min(1, baixo)][l-1] + qnt);}
else{ cima++; SumCima += tam[cima];}
}
for(int oo = baixo; oo>=1; oo--){
dp[l][r] = max(dp[l][r], dp[oo][l-1] + qnt);
}
maior = max(maior, dp[l][r]);
}
cout << maior << 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... |