#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
#define fi first
#define se second
const int N = 2e3+1;
int n,a[N],dp[N][1001][2];
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
for(int i = 1; i <= n; i++) cin >> a[i];
for(int i = 1; i <= n; i++){
for(int j = 1; j <= (i+1)/2; j++){
dp[i][j][0] = max(dp[i-1][j][1],dp[i-1][j][0]);
dp[i][j][1] = dp[i-1][j-1][0]+a[i];
}
}
for(int j = 1; j <= (n+1)/2; j++){
int ans = 0;
for(int i = 1; i <= n; i++) ans = max(ans,max(dp[i][j][0],dp[i][j][1]));
cout << ans << "\n";
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |