#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
ll n;
cin >> n;
vector<ll> v(n+1);
vector<vector<ll>> dp(n+1, vector<ll>(n+1, 0));
for(int i = 1;i<=n;i++)cin >> v[i];
for(int i = 1;i<=n;i++){
for(int j = 1;j<=n;j++){
if(i == 1 && j == 1)dp[i][j] = v[i];
else if(j > (i+1)/2)dp[i][j] = -1;
else{
dp[i][j] = max(dp[i-2][j-1] + v[i], dp[i-1][j]);
}
// cout << dp[i][j] << " ";
}
// cout << '\n';
}
for(int j = 1;j<=(n+1)/2;j++)cout << dp[n][j] << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
29 ms |
31792 KB |
Output is correct |
2 |
Correct |
33 ms |
31712 KB |
Output is correct |
3 |
Correct |
28 ms |
31692 KB |
Output is correct |
4 |
Correct |
29 ms |
31668 KB |
Output is correct |
5 |
Correct |
28 ms |
31744 KB |
Output is correct |
6 |
Correct |
28 ms |
31692 KB |
Output is correct |
7 |
Correct |
28 ms |
31664 KB |
Output is correct |
8 |
Correct |
28 ms |
31744 KB |
Output is correct |
9 |
Correct |
30 ms |
31744 KB |
Output is correct |
10 |
Correct |
29 ms |
31664 KB |
Output is correct |
11 |
Correct |
29 ms |
31692 KB |
Output is correct |
12 |
Correct |
29 ms |
31660 KB |
Output is correct |
13 |
Correct |
29 ms |
31732 KB |
Output is correct |
14 |
Correct |
30 ms |
31712 KB |
Output is correct |
15 |
Correct |
29 ms |
31668 KB |
Output is correct |
16 |
Correct |
29 ms |
31600 KB |
Output is correct |
17 |
Correct |
28 ms |
31660 KB |
Output is correct |
18 |
Correct |
29 ms |
31724 KB |
Output is correct |
19 |
Correct |
29 ms |
31616 KB |
Output is correct |
20 |
Correct |
28 ms |
31664 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
29 ms |
31792 KB |
Output is correct |
2 |
Correct |
33 ms |
31712 KB |
Output is correct |
3 |
Correct |
28 ms |
31692 KB |
Output is correct |
4 |
Correct |
29 ms |
31668 KB |
Output is correct |
5 |
Correct |
28 ms |
31744 KB |
Output is correct |
6 |
Correct |
28 ms |
31692 KB |
Output is correct |
7 |
Correct |
28 ms |
31664 KB |
Output is correct |
8 |
Correct |
28 ms |
31744 KB |
Output is correct |
9 |
Correct |
30 ms |
31744 KB |
Output is correct |
10 |
Correct |
29 ms |
31664 KB |
Output is correct |
11 |
Correct |
29 ms |
31692 KB |
Output is correct |
12 |
Correct |
29 ms |
31660 KB |
Output is correct |
13 |
Correct |
29 ms |
31732 KB |
Output is correct |
14 |
Correct |
30 ms |
31712 KB |
Output is correct |
15 |
Correct |
29 ms |
31668 KB |
Output is correct |
16 |
Correct |
29 ms |
31600 KB |
Output is correct |
17 |
Correct |
28 ms |
31660 KB |
Output is correct |
18 |
Correct |
29 ms |
31724 KB |
Output is correct |
19 |
Correct |
29 ms |
31616 KB |
Output is correct |
20 |
Correct |
28 ms |
31664 KB |
Output is correct |
21 |
Runtime error |
229 ms |
524292 KB |
Execution killed with signal 9 |
22 |
Halted |
0 ms |
0 KB |
- |