#include "bits/stdc++.h"
#define pb push_back
#define endl '\n'
#define fi first
#define se second
#define CDIV(a,b) (((a)+(b)-(1))/(b))
using ll = long long;
using ld = long double;
const ll inf = 1e17 + 37;
const ll mod = 1e9 + 7;
const ll N = 3000 + 1;
const ld eps = 1e-9;
const ld PI = acos((ld)-1);
template<typename T, size_t N>
std::ostream& operator<<(std::ostream& os, const std::array<T, N>& a);
template<typename T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& v);
template<typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, const std::pair<T1, T2>& p);
template<typename T>
std::ostream& operator<<(std::ostream& os, const std::set<T>& s);
template<typename T, typename cmp>
std::ostream& operator<<(std::ostream& os, const std::set<T, cmp>& s);
using namespace std;
void solve() {
ll n;
cin >> n;
vector<ll> v(n + 1);
for(ll i = 1; i <= n; ++i) {
cin >> v[i];
}
vector<vector<ll> > dp(n + 1, vector<ll>(n + 1));
dp[1][1] = v[1];
for(ll i = 2; i <= n; ++i) {
for(ll j = 1; j <= i/2 + i%2; ++j) {
dp[i][j] = max(dp[i - 1][j], dp[i - 2][j - 1] + v[i]);
}
}
for(ll j = 1; j <= n/2 + n%2; ++j)
cout << dp[n][j] << endl;
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
solve();
}
/*
5
3 5 1 7 6
*/
template<typename T, size_t N>
std::ostream& operator<<(std::ostream& os, const std::array<T, N>& a) {
os << "[";
for(size_t i = 0; i + 1 < N; ++i) {
os << a[i] << ", ";
}
if(N > 0)
os << a[N - 1];
os << "]";
return os;
}
template<typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, const std::pair<T1, T2>& p) {
os << "(" << p.first << ", " << p.second << ") ";
return os;
}
template<typename T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& v) {
os << '[';
for(auto x : v)
os << x << ", ";
os << "] ";
return os;
}
template<typename T>
std::ostream& operator<<(std::ostream& os, const std::set<T>& s) {
os << "{";
for(auto x : s)
os << x << ", ";
os << "} ";
return os;
}
//
template<typename T, typename cmp>
std::ostream& operator<<(std::ostream& os, const std::set<T, cmp>& s) {
os << "{";
for(auto x : s)
os << x << ", ";
os << "} ";
return os;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
31856 KB |
Output is correct |
2 |
Correct |
12 ms |
31756 KB |
Output is correct |
3 |
Correct |
13 ms |
31840 KB |
Output is correct |
4 |
Correct |
13 ms |
31836 KB |
Output is correct |
5 |
Correct |
13 ms |
31700 KB |
Output is correct |
6 |
Correct |
12 ms |
31776 KB |
Output is correct |
7 |
Correct |
13 ms |
31836 KB |
Output is correct |
8 |
Correct |
13 ms |
31708 KB |
Output is correct |
9 |
Correct |
12 ms |
31724 KB |
Output is correct |
10 |
Correct |
12 ms |
31836 KB |
Output is correct |
11 |
Correct |
11 ms |
31836 KB |
Output is correct |
12 |
Correct |
11 ms |
31884 KB |
Output is correct |
13 |
Correct |
12 ms |
31836 KB |
Output is correct |
14 |
Correct |
16 ms |
31836 KB |
Output is correct |
15 |
Correct |
16 ms |
31836 KB |
Output is correct |
16 |
Correct |
13 ms |
31836 KB |
Output is correct |
17 |
Correct |
12 ms |
31836 KB |
Output is correct |
18 |
Correct |
16 ms |
31716 KB |
Output is correct |
19 |
Correct |
12 ms |
31836 KB |
Output is correct |
20 |
Correct |
12 ms |
31800 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
31856 KB |
Output is correct |
2 |
Correct |
12 ms |
31756 KB |
Output is correct |
3 |
Correct |
13 ms |
31840 KB |
Output is correct |
4 |
Correct |
13 ms |
31836 KB |
Output is correct |
5 |
Correct |
13 ms |
31700 KB |
Output is correct |
6 |
Correct |
12 ms |
31776 KB |
Output is correct |
7 |
Correct |
13 ms |
31836 KB |
Output is correct |
8 |
Correct |
13 ms |
31708 KB |
Output is correct |
9 |
Correct |
12 ms |
31724 KB |
Output is correct |
10 |
Correct |
12 ms |
31836 KB |
Output is correct |
11 |
Correct |
11 ms |
31836 KB |
Output is correct |
12 |
Correct |
11 ms |
31884 KB |
Output is correct |
13 |
Correct |
12 ms |
31836 KB |
Output is correct |
14 |
Correct |
16 ms |
31836 KB |
Output is correct |
15 |
Correct |
16 ms |
31836 KB |
Output is correct |
16 |
Correct |
13 ms |
31836 KB |
Output is correct |
17 |
Correct |
12 ms |
31836 KB |
Output is correct |
18 |
Correct |
16 ms |
31716 KB |
Output is correct |
19 |
Correct |
12 ms |
31836 KB |
Output is correct |
20 |
Correct |
12 ms |
31800 KB |
Output is correct |
21 |
Runtime error |
198 ms |
524288 KB |
Execution killed with signal 9 |
22 |
Halted |
0 ms |
0 KB |
- |