#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
typedef long long int ll;
const int N=2e3+5;
ll dp[N][N];
ll a[N];
int main()
{
ios_base:: sync_with_stdio(false); cin.tie(0);
int n; cin>>n;
for(int i=1; i<=n; i++) {
cin>>a[i];
dp[i][1]=max(dp[i-1][1],a[i]);
}
for(int k=2; k<=(n+1/2); k++) {
for(int i=2*k-1; i<=n; i++) {
dp[i][k]=max(dp[i-1][k],dp[i-2][k-1]+a[i]);
}
}
for(int i=1; i<=(n+1)/2; i++) {
cout<<dp[n][i]<<endl;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
16248 KB |
Output is correct |
2 |
Correct |
21 ms |
16248 KB |
Output is correct |
3 |
Correct |
20 ms |
16248 KB |
Output is correct |
4 |
Correct |
20 ms |
16248 KB |
Output is correct |
5 |
Correct |
21 ms |
16248 KB |
Output is correct |
6 |
Correct |
20 ms |
16248 KB |
Output is correct |
7 |
Correct |
21 ms |
16248 KB |
Output is correct |
8 |
Correct |
21 ms |
16248 KB |
Output is correct |
9 |
Correct |
21 ms |
16292 KB |
Output is correct |
10 |
Correct |
20 ms |
16248 KB |
Output is correct |
11 |
Correct |
20 ms |
16248 KB |
Output is correct |
12 |
Correct |
20 ms |
16228 KB |
Output is correct |
13 |
Correct |
21 ms |
16284 KB |
Output is correct |
14 |
Correct |
20 ms |
16248 KB |
Output is correct |
15 |
Correct |
20 ms |
16248 KB |
Output is correct |
16 |
Correct |
20 ms |
16248 KB |
Output is correct |
17 |
Correct |
25 ms |
16248 KB |
Output is correct |
18 |
Correct |
24 ms |
16248 KB |
Output is correct |
19 |
Correct |
25 ms |
16272 KB |
Output is correct |
20 |
Correct |
23 ms |
16248 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
16248 KB |
Output is correct |
2 |
Correct |
21 ms |
16248 KB |
Output is correct |
3 |
Correct |
20 ms |
16248 KB |
Output is correct |
4 |
Correct |
20 ms |
16248 KB |
Output is correct |
5 |
Correct |
21 ms |
16248 KB |
Output is correct |
6 |
Correct |
20 ms |
16248 KB |
Output is correct |
7 |
Correct |
21 ms |
16248 KB |
Output is correct |
8 |
Correct |
21 ms |
16248 KB |
Output is correct |
9 |
Correct |
21 ms |
16292 KB |
Output is correct |
10 |
Correct |
20 ms |
16248 KB |
Output is correct |
11 |
Correct |
20 ms |
16248 KB |
Output is correct |
12 |
Correct |
20 ms |
16228 KB |
Output is correct |
13 |
Correct |
21 ms |
16284 KB |
Output is correct |
14 |
Correct |
20 ms |
16248 KB |
Output is correct |
15 |
Correct |
20 ms |
16248 KB |
Output is correct |
16 |
Correct |
20 ms |
16248 KB |
Output is correct |
17 |
Correct |
25 ms |
16248 KB |
Output is correct |
18 |
Correct |
24 ms |
16248 KB |
Output is correct |
19 |
Correct |
25 ms |
16272 KB |
Output is correct |
20 |
Correct |
23 ms |
16248 KB |
Output is correct |
21 |
Runtime error |
36 ms |
16940 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
22 |
Halted |
0 ms |
0 KB |
- |