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>
#define fr first
#define sc second
#define pb push_back
#define mk make_pair
#define ll long long
#define OK puts("OK")
#define sz(s) (int)s.size()
#define all(s) s.begin(), s.end()
using namespace std;
const int N = 2010;
const ll inf = 1e15+7;
int n, a[N];
ll dp[N][N];
int main() {
cin >> n;
for(int i = 0; i <= n; i++)
for(int j = 0; j <= n; j++)
dp[i][j] = -inf;
dp[0][0] = 0;
for(int i = 1; i <= n; i++) {
cin >> a[i];
if(i == 1) {
dp[1][0] = 0,
dp[1][1] = a[1];
}
else {
for(int j = 0; j <= n; j++) {
dp[i][j] = dp[i - 1][j];
if(j > 0)
dp[i][j] = max(dp[i][j], dp[i - 2][j - 1] + a[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... |