This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define lli long long
#define INF LONG_LONG_MAX
#define pb push_back
#define mp make_pair
#define st first
#define nd second
#define endl '\n'
#define max(aa, bb) (aa > bb ? aa:bb)
#define min(aa, bb) (aa < bb ? aa:bb)
#define all(aa) aa.begin(), aa.end()
int main(){
#ifdef ONLINE_JUDGE
freopen("zgir.gir", "r", stdin);
freopen("zcik.cik", "w", stdout);
#endif
lli n;
cin>>n;
vector<lli> v(n);
for(auto &it:v) cin>>it;
lli dp[2006][1006];
memset(dp, -1, sizeof(dp));
function<lli(lli, lli)> f= [&] (lli i, lli r) -> lli{
if(r<=0) return 0;
if(i>=n) return -INF;
if(dp[i][r]!=-1) return dp[i][r];
return dp[i][r]=max(f(i+2, r-1)+v[i], f(i+1, r));
};
for(lli j=1;j<=(n+1)/2;j++){
cout<<f(0, j)<<endl;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |