#include <bits/stdc++.h>
using namespace std;
const int N = 2002;
long long dp[N][N];
long long a[N];
int main(){
ios_base::sync_with_stdio(false);
int n;
cin>>n;
memset(dp,-1,sizeof(dp));
for(int i = 1;i<=n;i++){
cin>>a[i];
dp[i][1] = max(dp[i][1],dp[i-1][1]);
dp[i][1] = max(dp[i][1],a[i]);
}
cout<<dp[n][1]<<endl;
for(int k = 2;k<=(n+1)/2;k++){
for(int i = 1;i<=n;i++){
if(dp[i-1][k]!=-1) dp[i][k] = max(dp[i][k],dp[i-1][k]);
if(i-2>=0 && dp[i-2][k-1]!=-1) dp[i][k] = max(dp[i][k],dp[i-2][k-1]+a[i]);
}
cout<<dp[n][k]<<endl;
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
52 ms |
31736 KB |
Output is correct |
2 |
Correct |
52 ms |
31736 KB |
Output is correct |
3 |
Correct |
53 ms |
31736 KB |
Output is correct |
4 |
Correct |
53 ms |
31736 KB |
Output is correct |
5 |
Correct |
53 ms |
31736 KB |
Output is correct |
6 |
Correct |
53 ms |
31736 KB |
Output is correct |
7 |
Correct |
55 ms |
31736 KB |
Output is correct |
8 |
Correct |
53 ms |
31788 KB |
Output is correct |
9 |
Correct |
52 ms |
31736 KB |
Output is correct |
10 |
Correct |
54 ms |
31736 KB |
Output is correct |
11 |
Correct |
53 ms |
31864 KB |
Output is correct |
12 |
Correct |
53 ms |
31736 KB |
Output is correct |
13 |
Correct |
53 ms |
31736 KB |
Output is correct |
14 |
Correct |
55 ms |
31736 KB |
Output is correct |
15 |
Correct |
54 ms |
31740 KB |
Output is correct |
16 |
Correct |
54 ms |
31844 KB |
Output is correct |
17 |
Correct |
53 ms |
31736 KB |
Output is correct |
18 |
Correct |
59 ms |
31736 KB |
Output is correct |
19 |
Correct |
61 ms |
31756 KB |
Output is correct |
20 |
Correct |
62 ms |
31736 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
52 ms |
31736 KB |
Output is correct |
2 |
Correct |
52 ms |
31736 KB |
Output is correct |
3 |
Correct |
53 ms |
31736 KB |
Output is correct |
4 |
Correct |
53 ms |
31736 KB |
Output is correct |
5 |
Correct |
53 ms |
31736 KB |
Output is correct |
6 |
Correct |
53 ms |
31736 KB |
Output is correct |
7 |
Correct |
55 ms |
31736 KB |
Output is correct |
8 |
Correct |
53 ms |
31788 KB |
Output is correct |
9 |
Correct |
52 ms |
31736 KB |
Output is correct |
10 |
Correct |
54 ms |
31736 KB |
Output is correct |
11 |
Correct |
53 ms |
31864 KB |
Output is correct |
12 |
Correct |
53 ms |
31736 KB |
Output is correct |
13 |
Correct |
53 ms |
31736 KB |
Output is correct |
14 |
Correct |
55 ms |
31736 KB |
Output is correct |
15 |
Correct |
54 ms |
31740 KB |
Output is correct |
16 |
Correct |
54 ms |
31844 KB |
Output is correct |
17 |
Correct |
53 ms |
31736 KB |
Output is correct |
18 |
Correct |
59 ms |
31736 KB |
Output is correct |
19 |
Correct |
61 ms |
31756 KB |
Output is correct |
20 |
Correct |
62 ms |
31736 KB |
Output is correct |
21 |
Runtime error |
71 ms |
64168 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
22 |
Halted |
0 ms |
0 KB |
- |