#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;
#define F first
#define S second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define SZ(x) (int)(x).size()
#define int ll
const int N = 2010;
int a[N], dp[N][N];
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 0; i <= n; i++) {
for (int j = 1; j <= n; j++) {
dp[i][j] = -1e18;
}
}
dp[1][1] = a[1];
for (int i = 2; i <= n; i++) {
for (int j = 1; j <= i; j++) {
dp[i][j] = max(dp[i - 1][j], dp[i - 2][j - 1] + a[i]);
}
}
for (int i = 1; i <= (n + 1) / 2; i++) {
cout << dp[n][i] << '\n';
}
cout << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
31872 KB |
Output is correct |
2 |
Correct |
22 ms |
31872 KB |
Output is correct |
3 |
Correct |
22 ms |
31872 KB |
Output is correct |
4 |
Correct |
30 ms |
31872 KB |
Output is correct |
5 |
Correct |
23 ms |
31872 KB |
Output is correct |
6 |
Correct |
23 ms |
31872 KB |
Output is correct |
7 |
Correct |
22 ms |
31872 KB |
Output is correct |
8 |
Correct |
22 ms |
31872 KB |
Output is correct |
9 |
Correct |
22 ms |
31872 KB |
Output is correct |
10 |
Correct |
23 ms |
31872 KB |
Output is correct |
11 |
Correct |
23 ms |
31872 KB |
Output is correct |
12 |
Correct |
23 ms |
32000 KB |
Output is correct |
13 |
Correct |
23 ms |
31872 KB |
Output is correct |
14 |
Correct |
23 ms |
31872 KB |
Output is correct |
15 |
Correct |
24 ms |
31872 KB |
Output is correct |
16 |
Correct |
22 ms |
31872 KB |
Output is correct |
17 |
Correct |
23 ms |
31872 KB |
Output is correct |
18 |
Correct |
23 ms |
31872 KB |
Output is correct |
19 |
Correct |
23 ms |
31872 KB |
Output is correct |
20 |
Correct |
25 ms |
32248 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
31872 KB |
Output is correct |
2 |
Correct |
22 ms |
31872 KB |
Output is correct |
3 |
Correct |
22 ms |
31872 KB |
Output is correct |
4 |
Correct |
30 ms |
31872 KB |
Output is correct |
5 |
Correct |
23 ms |
31872 KB |
Output is correct |
6 |
Correct |
23 ms |
31872 KB |
Output is correct |
7 |
Correct |
22 ms |
31872 KB |
Output is correct |
8 |
Correct |
22 ms |
31872 KB |
Output is correct |
9 |
Correct |
22 ms |
31872 KB |
Output is correct |
10 |
Correct |
23 ms |
31872 KB |
Output is correct |
11 |
Correct |
23 ms |
31872 KB |
Output is correct |
12 |
Correct |
23 ms |
32000 KB |
Output is correct |
13 |
Correct |
23 ms |
31872 KB |
Output is correct |
14 |
Correct |
23 ms |
31872 KB |
Output is correct |
15 |
Correct |
24 ms |
31872 KB |
Output is correct |
16 |
Correct |
22 ms |
31872 KB |
Output is correct |
17 |
Correct |
23 ms |
31872 KB |
Output is correct |
18 |
Correct |
23 ms |
31872 KB |
Output is correct |
19 |
Correct |
23 ms |
31872 KB |
Output is correct |
20 |
Correct |
25 ms |
32248 KB |
Output is correct |
21 |
Runtime error |
7 ms |
640 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
22 |
Halted |
0 ms |
0 KB |
- |