#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
int n2 = (n+1)/2;
vector<int> candies(n);
for(int i = 0; i < n; i++)
{
cin >> candies[i];
}
vector<vector<ll>> dp(n2+1); //k, index
for(int k = 0; k < n2+1; k++)
{
dp[k] = vector<ll>(n+1);
if(k > 0)
{
dp[k][1] = candies[0];
}
}
for(int k = 1; k < n2+1; k++)
{
for(int i = 2; i < n+1; i++)
{
if(2*(k-1) < i) dp[k][i] = max(dp[k][i-1], dp[k-1][i-2] + candies[i-1]);
}
cout << dp[k][n] << "\n";
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |