This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/* Author : Mychecksdead */
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD (1000000000+7)
#define MOD1 (998244353)
#define pb push_back
#define all(x) x.begin(), x.end()
#define en cout << '\n'
#define ff first
#define ss second
const int N = 2000+100, M = 1e5+10, K = 52, MX = 30;
int n;
ll a[N], dp[N][N];
void solve(){
cin >> n;
for(int i = 1; i <= n; ++i){
cin >> a[i];
}
for(int i = 0; i <= n; ++i) for(int j = 0; j <= n; ++j) dp[i][j] = 0;
for(int i = 0; i <= n; ++i) dp[0][i] = -1e15;
dp[0][0] = 0;
for(int i = 1; i <= n; ++i){
for(int j = 0; j <= i; ++j){
dp[i][j] = dp[i - 1][j];
if(j>0)
dp[i][j] = max(dp[i][j], dp[i - 2][j - 1] + a[i]);
}
}
for(int j = 1; j <= (n+1)/2; ++j){
ll mx = 0;
for(int i = 1; i <= n; ++i) mx = max(mx, dp[i][j]);
cout << mx << '\n';
}
}
int main(){
cin.tie(0); ios::sync_with_stdio(0);
int tt = 1, aa;
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
while(tt--){
solve();
en;
}
cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" seconds\n";
return 0;
}
Compilation message (stderr)
candies.cpp: In function 'int main()':
candies.cpp:42:15: warning: unused variable 'aa' [-Wunused-variable]
42 | int tt = 1, aa;
| ^~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |