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 <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>
using namespace std;
#define int long long
const int N = 2001;
const int INF = 1e18 + 239;
int a[N];
int dp[N][N];
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
for (int i = 0; i < N; i++) {
fill(dp[i], dp[i] + N, -INF);
}
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
dp[0][0] = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= (i + 1) / 2; j++) {
int c = a[i - 1];
if (i - 2 >= 0 && j - 1 >= 0) {
c += dp[i - 2][j - 1];
}
dp[i][j] = max(dp[i - 1][j], c);
}
dp[i][0] = 0;
}
for (int i = 1; i <= (n + 1) / 2; i++) {
cout << dp[n][i] << ' ';
}
cout << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |