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 ll long long
int main(){
ios::sync_with_stdio(0); cin.tie(0);
int n; cin>>n;
vector<ll> v(n); for(ll &i : v) cin>>i;
int k = (n+1)/2;
vector<vector<ll>> dp(n,vector<ll>(k+1,-1e18));
dp[0][0]=0;
dp[0][1]=v[0];
for(int i=1;i<n;i++){
dp[i][0]=0;
for(int j = 1;j <= (i/2 + 1);j++){
ll l = 0;
if(i>1) l = dp[i-2][j-1];
dp[i][j] = max(dp[i-1][j], l + v[i]);
}
}
/*for(int i=0;i<n;i++){
for(int j=0;j<=k;j++){
cout<<dp[i][j]<<' ';
}
cout<<endl;
}*/
for(int i=1;i<=k;i++) cout<<dp[n-1][i]<<endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |