#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
long long a[n];
for(int i=0;i<n;i++)cin>>a[i];
long long dp[(n+n%2)/2][n];
dp[0][0]=a[0];
for(int i=2;i<n;i+=2)
dp[i/2][i]=a[i]+dp[i/2-1][i-2];
for(int i=1;i<n;i++)
dp[0][i]=max(a[i],dp[0][i-1]);
for(int i=1;i<(n+n%2)/2;i++)
for(int j=2*i+1;j<n;j++)
dp[i][j]=max(dp[i][j-1],a[j]+dp[i-1][j-2]);
for(int i=0;i<(n+n%2)/2;i++)
cout<<dp[i][n-1]<<endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
15960 KB |
Output is correct |
2 |
Correct |
15 ms |
15960 KB |
Output is correct |
3 |
Correct |
13 ms |
15964 KB |
Output is correct |
4 |
Correct |
15 ms |
16076 KB |
Output is correct |
5 |
Correct |
15 ms |
15964 KB |
Output is correct |
6 |
Correct |
13 ms |
15964 KB |
Output is correct |
7 |
Correct |
14 ms |
15964 KB |
Output is correct |
8 |
Correct |
13 ms |
16216 KB |
Output is correct |
9 |
Correct |
13 ms |
15964 KB |
Output is correct |
10 |
Correct |
13 ms |
15964 KB |
Output is correct |
11 |
Correct |
13 ms |
15964 KB |
Output is correct |
12 |
Correct |
13 ms |
15964 KB |
Output is correct |
13 |
Correct |
13 ms |
15960 KB |
Output is correct |
14 |
Correct |
13 ms |
15964 KB |
Output is correct |
15 |
Correct |
13 ms |
15964 KB |
Output is correct |
16 |
Correct |
13 ms |
15964 KB |
Output is correct |
17 |
Correct |
13 ms |
15960 KB |
Output is correct |
18 |
Correct |
16 ms |
15964 KB |
Output is correct |
19 |
Correct |
13 ms |
15964 KB |
Output is correct |
20 |
Correct |
13 ms |
15964 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
15960 KB |
Output is correct |
2 |
Correct |
15 ms |
15960 KB |
Output is correct |
3 |
Correct |
13 ms |
15964 KB |
Output is correct |
4 |
Correct |
15 ms |
16076 KB |
Output is correct |
5 |
Correct |
15 ms |
15964 KB |
Output is correct |
6 |
Correct |
13 ms |
15964 KB |
Output is correct |
7 |
Correct |
14 ms |
15964 KB |
Output is correct |
8 |
Correct |
13 ms |
16216 KB |
Output is correct |
9 |
Correct |
13 ms |
15964 KB |
Output is correct |
10 |
Correct |
13 ms |
15964 KB |
Output is correct |
11 |
Correct |
13 ms |
15964 KB |
Output is correct |
12 |
Correct |
13 ms |
15964 KB |
Output is correct |
13 |
Correct |
13 ms |
15960 KB |
Output is correct |
14 |
Correct |
13 ms |
15964 KB |
Output is correct |
15 |
Correct |
13 ms |
15964 KB |
Output is correct |
16 |
Correct |
13 ms |
15964 KB |
Output is correct |
17 |
Correct |
13 ms |
15960 KB |
Output is correct |
18 |
Correct |
16 ms |
15964 KB |
Output is correct |
19 |
Correct |
13 ms |
15964 KB |
Output is correct |
20 |
Correct |
13 ms |
15964 KB |
Output is correct |
21 |
Runtime error |
334 ms |
524288 KB |
Execution killed with signal 9 |
22 |
Halted |
0 ms |
0 KB |
- |