#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
const int mxN = (int)2e3+10;
const int LINF = (int)2e18;
int n, a[mxN], dp[mxN][mxN/2];
int32_t main() {
ios_base::sync_with_stdio(false); cin.tie(0);
cin >> n;
for(int i = 1; i <= n; i++) cin >> a[i];
for(int i = 0; i <= n; i++)
for(int j = 0; j <= (n+1)/2; j++)
dp[i][j] = -LINF;
dp[0][0]=0;
for(int i = 1; i <= n; i++){
for(int j = 0; j <= min(i,(n+1)/2); j++){
dp[i][j] = dp[i-1][j];
if(j==1) dp[i][j] = max(dp[i][j], a[i]);
else if(i>1) 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 |
9 ms |
16096 KB |
Output is correct |
2 |
Correct |
11 ms |
16084 KB |
Output is correct |
3 |
Correct |
11 ms |
16084 KB |
Output is correct |
4 |
Correct |
10 ms |
16088 KB |
Output is correct |
5 |
Correct |
10 ms |
16084 KB |
Output is correct |
6 |
Correct |
10 ms |
16088 KB |
Output is correct |
7 |
Correct |
10 ms |
16052 KB |
Output is correct |
8 |
Correct |
11 ms |
16084 KB |
Output is correct |
9 |
Correct |
11 ms |
16084 KB |
Output is correct |
10 |
Correct |
10 ms |
16092 KB |
Output is correct |
11 |
Correct |
9 ms |
16084 KB |
Output is correct |
12 |
Correct |
10 ms |
16100 KB |
Output is correct |
13 |
Correct |
10 ms |
16084 KB |
Output is correct |
14 |
Correct |
10 ms |
16092 KB |
Output is correct |
15 |
Correct |
10 ms |
16084 KB |
Output is correct |
16 |
Correct |
9 ms |
16100 KB |
Output is correct |
17 |
Correct |
10 ms |
16084 KB |
Output is correct |
18 |
Correct |
10 ms |
16088 KB |
Output is correct |
19 |
Correct |
10 ms |
16084 KB |
Output is correct |
20 |
Correct |
10 ms |
16084 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
16096 KB |
Output is correct |
2 |
Correct |
11 ms |
16084 KB |
Output is correct |
3 |
Correct |
11 ms |
16084 KB |
Output is correct |
4 |
Correct |
10 ms |
16088 KB |
Output is correct |
5 |
Correct |
10 ms |
16084 KB |
Output is correct |
6 |
Correct |
10 ms |
16088 KB |
Output is correct |
7 |
Correct |
10 ms |
16052 KB |
Output is correct |
8 |
Correct |
11 ms |
16084 KB |
Output is correct |
9 |
Correct |
11 ms |
16084 KB |
Output is correct |
10 |
Correct |
10 ms |
16092 KB |
Output is correct |
11 |
Correct |
9 ms |
16084 KB |
Output is correct |
12 |
Correct |
10 ms |
16100 KB |
Output is correct |
13 |
Correct |
10 ms |
16084 KB |
Output is correct |
14 |
Correct |
10 ms |
16092 KB |
Output is correct |
15 |
Correct |
10 ms |
16084 KB |
Output is correct |
16 |
Correct |
9 ms |
16100 KB |
Output is correct |
17 |
Correct |
10 ms |
16084 KB |
Output is correct |
18 |
Correct |
10 ms |
16088 KB |
Output is correct |
19 |
Correct |
10 ms |
16084 KB |
Output is correct |
20 |
Correct |
10 ms |
16084 KB |
Output is correct |
21 |
Runtime error |
2 ms |
596 KB |
Execution killed with signal 11 |
22 |
Halted |
0 ms |
0 KB |
- |