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
#define X first
#define Y second
int n;
int ar[500005];
int dp[5010][5010];
signed main(){
cin>>n;
for(int i=1;i<=n;i++){
cin>>ar[i];
}
for(int i=0;i<=n;i++){
for(int j=1;j<=n;j++){
dp[i][j]=-1e16;
}
}
dp[0][0]=0;
dp[1][0]=0;
dp[1][1]=ar[1];
for(int i=2;i<=n;i++){
for(int j=1;j<=i;j++){
dp[i][j]=max(dp[i-1][j],dp[i-2][j-1]+ar[i]);
}
}
for(int i=1;i<=(n+1)/2;i++){
cout<<dp[n][i]<<"\n";
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |