#include <bits/stdc++.h>
using namespace std;
#define dbgv(v) cout<<#v<<" = "; f(i,0,v.size()) cout<<v[i]<<" "; cout<<endl
#define dbga(a,x,y) cout<<#a<<" = "; f(i,x,y) cout<<a[i]<<" "; cout<<endl
#define erorp(x) cout<<#x<<"={"<<(x.F)<<" , "<<x.S<<"}"<<endl
#define eror(x) cout<<#x<<'='<<(x)<<endl
#define f_(i,a,b) for(int i=a;i>=b;i--)
#define f(i,a,b) for(int i=a;i<b;i++)
#define nb(x) __builtin_popcount(x)
#define all(v) v.begin(),v.end()
#define bit(n,k) (((n)>>(k))&1)
#define Add(x,y) x=(x+y)%mod
#define maxm(a,b) a=max(a,b)
#define minm(a,b) a=min(a,b)
#define lst(x) x[x.size()-1]
#define sz(x) int(x.size())
#define mp make_pair
#define ll long long
#define pb push_back
#define S second
#define F first
#define int ll
const int N=5555,inf=1e16;
int n,t,a[N],dp[N][N];
main(){
srand(time(NULL));
cin>>n;
f(i,1,n+1){
cin>>a[i];
//a[i]=rand()%100;
//cout<<a[i]<<" ";
}
f(i,0,N) f(j,1,N) dp[i][j]=-inf;
dp[1][1]=a[1];
f(i,2,n+1){
f(j,1,n+1){
dp[i][j]=max(dp[i-1][j],dp[i-2][j-1]+a[i]);
}
}
f(i,1,(n+1)/2+1){
cout<<dp[n][i]<<" ";
}
}
Compilation message
candies.cpp:28:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
28 | main(){
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
95 ms |
241848 KB |
Output is correct |
2 |
Correct |
95 ms |
241744 KB |
Output is correct |
3 |
Correct |
96 ms |
241744 KB |
Output is correct |
4 |
Correct |
98 ms |
241816 KB |
Output is correct |
5 |
Correct |
94 ms |
241748 KB |
Output is correct |
6 |
Correct |
94 ms |
241788 KB |
Output is correct |
7 |
Correct |
97 ms |
241856 KB |
Output is correct |
8 |
Correct |
101 ms |
241756 KB |
Output is correct |
9 |
Correct |
99 ms |
241860 KB |
Output is correct |
10 |
Correct |
96 ms |
241848 KB |
Output is correct |
11 |
Correct |
95 ms |
241776 KB |
Output is correct |
12 |
Correct |
95 ms |
241912 KB |
Output is correct |
13 |
Correct |
94 ms |
241860 KB |
Output is correct |
14 |
Correct |
94 ms |
241756 KB |
Output is correct |
15 |
Correct |
95 ms |
241988 KB |
Output is correct |
16 |
Correct |
96 ms |
241812 KB |
Output is correct |
17 |
Correct |
96 ms |
241828 KB |
Output is correct |
18 |
Correct |
96 ms |
241860 KB |
Output is correct |
19 |
Correct |
96 ms |
241792 KB |
Output is correct |
20 |
Correct |
95 ms |
241744 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
95 ms |
241848 KB |
Output is correct |
2 |
Correct |
95 ms |
241744 KB |
Output is correct |
3 |
Correct |
96 ms |
241744 KB |
Output is correct |
4 |
Correct |
98 ms |
241816 KB |
Output is correct |
5 |
Correct |
94 ms |
241748 KB |
Output is correct |
6 |
Correct |
94 ms |
241788 KB |
Output is correct |
7 |
Correct |
97 ms |
241856 KB |
Output is correct |
8 |
Correct |
101 ms |
241756 KB |
Output is correct |
9 |
Correct |
99 ms |
241860 KB |
Output is correct |
10 |
Correct |
96 ms |
241848 KB |
Output is correct |
11 |
Correct |
95 ms |
241776 KB |
Output is correct |
12 |
Correct |
95 ms |
241912 KB |
Output is correct |
13 |
Correct |
94 ms |
241860 KB |
Output is correct |
14 |
Correct |
94 ms |
241756 KB |
Output is correct |
15 |
Correct |
95 ms |
241988 KB |
Output is correct |
16 |
Correct |
96 ms |
241812 KB |
Output is correct |
17 |
Correct |
96 ms |
241828 KB |
Output is correct |
18 |
Correct |
96 ms |
241860 KB |
Output is correct |
19 |
Correct |
96 ms |
241792 KB |
Output is correct |
20 |
Correct |
95 ms |
241744 KB |
Output is correct |
21 |
Runtime error |
6 ms |
452 KB |
Execution killed with signal 11 |
22 |
Halted |
0 ms |
0 KB |
- |