#include <bits/stdc++.h>
using namespace std;
#define fi first
#define sc second
const int MAXN = 505;
int dp[MAXN][MAXN], d[MAXN], sp[MAXN];
int sum(int i, int j){
return sp[j] - sp[i-1];
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n; cin>>n;
for(int i = 1; i <= n; i++){
cin>>d[i];
sp[i] = sp[i-1]+d[i];
}
int ans = 0;
for(int r = n-1; r >= 1; r--){
set<pair<int,int>> st;
for(int j = r+1; j < n; j++)st.insert({sum(r+1,j), dp[r+1][j+1]});
int qtd = 0;
for(int l = r; l >= 1; l--){
dp[l][r] = max(dp[l+1][r+1], dp[l][r+1]);
if(l!=r){
auto it = st.lower_bound({sum(l+1,r),0});
if(it == st.end() || it->fi > sum(l+1,r))continue;
qtd++;
dp[l][r] = max(dp[l][r], (it->sc) + qtd);
}
ans = max(ans,dp[l][r]);
}
}
cout<<ans<<"\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
1372 KB |
Output is correct |
2 |
Incorrect |
7 ms |
1372 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |