#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";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
31 ms |
31864 KB |
Output is correct |
2 |
Correct |
32 ms |
31888 KB |
Output is correct |
3 |
Correct |
32 ms |
32116 KB |
Output is correct |
4 |
Correct |
33 ms |
32132 KB |
Output is correct |
5 |
Correct |
32 ms |
32132 KB |
Output is correct |
6 |
Correct |
32 ms |
32204 KB |
Output is correct |
7 |
Correct |
33 ms |
32224 KB |
Output is correct |
8 |
Correct |
32 ms |
32340 KB |
Output is correct |
9 |
Correct |
31 ms |
32456 KB |
Output is correct |
10 |
Correct |
33 ms |
32456 KB |
Output is correct |
11 |
Correct |
32 ms |
32456 KB |
Output is correct |
12 |
Correct |
32 ms |
32520 KB |
Output is correct |
13 |
Correct |
32 ms |
32520 KB |
Output is correct |
14 |
Correct |
32 ms |
32520 KB |
Output is correct |
15 |
Correct |
34 ms |
32520 KB |
Output is correct |
16 |
Correct |
32 ms |
32520 KB |
Output is correct |
17 |
Correct |
32 ms |
32624 KB |
Output is correct |
18 |
Correct |
35 ms |
32668 KB |
Output is correct |
19 |
Correct |
31 ms |
32668 KB |
Output is correct |
20 |
Correct |
31 ms |
32668 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
31 ms |
31864 KB |
Output is correct |
2 |
Correct |
32 ms |
31888 KB |
Output is correct |
3 |
Correct |
32 ms |
32116 KB |
Output is correct |
4 |
Correct |
33 ms |
32132 KB |
Output is correct |
5 |
Correct |
32 ms |
32132 KB |
Output is correct |
6 |
Correct |
32 ms |
32204 KB |
Output is correct |
7 |
Correct |
33 ms |
32224 KB |
Output is correct |
8 |
Correct |
32 ms |
32340 KB |
Output is correct |
9 |
Correct |
31 ms |
32456 KB |
Output is correct |
10 |
Correct |
33 ms |
32456 KB |
Output is correct |
11 |
Correct |
32 ms |
32456 KB |
Output is correct |
12 |
Correct |
32 ms |
32520 KB |
Output is correct |
13 |
Correct |
32 ms |
32520 KB |
Output is correct |
14 |
Correct |
32 ms |
32520 KB |
Output is correct |
15 |
Correct |
34 ms |
32520 KB |
Output is correct |
16 |
Correct |
32 ms |
32520 KB |
Output is correct |
17 |
Correct |
32 ms |
32624 KB |
Output is correct |
18 |
Correct |
35 ms |
32668 KB |
Output is correct |
19 |
Correct |
31 ms |
32668 KB |
Output is correct |
20 |
Correct |
31 ms |
32668 KB |
Output is correct |
21 |
Runtime error |
268 ms |
64524 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
22 |
Halted |
0 ms |
0 KB |
- |