// vaziat meshki-ghermeze !
#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " : " << x << '\n'
using namespace std;
typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;
const ll Mod = 1000000007LL;
const int N = 2e3 + 10;
const ll Inf = 2242545357980376863LL;
const ll Log = 30;
ll dp[N][N];
ll a[N];
int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
for(int i = 0; i < N; i++)
fill(dp[i], dp[i] + N, -Inf);
int n;
cin >> n;
dp[0][0] = 0;
for(int i = 1; i <= n; i++){
cin >> a[i];
for(int j = 1; j <= i; j++){
dp[i][j] = max(dp[i - 1][j], dp[i - 2][j - 1] + a[i]);
}
dp[i][0] = 0;
}
int sz = (n + 1) / 2;
ll mx = Inf;
for(int i = 1; i + 1 <= sz; i++){
assert(mx >= dp[n][i + 1] - dp[n][i]);
mx = dp[n][i + 1] - dp[n][i];
}
for(int i = 1; i <= sz; i++) cout << dp[n][i] << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
31980 KB |
Output is correct |
2 |
Correct |
22 ms |
31980 KB |
Output is correct |
3 |
Correct |
22 ms |
31980 KB |
Output is correct |
4 |
Correct |
23 ms |
31980 KB |
Output is correct |
5 |
Correct |
22 ms |
31980 KB |
Output is correct |
6 |
Correct |
22 ms |
31980 KB |
Output is correct |
7 |
Correct |
22 ms |
31980 KB |
Output is correct |
8 |
Correct |
22 ms |
31980 KB |
Output is correct |
9 |
Correct |
22 ms |
31980 KB |
Output is correct |
10 |
Correct |
22 ms |
31980 KB |
Output is correct |
11 |
Correct |
24 ms |
31980 KB |
Output is correct |
12 |
Correct |
22 ms |
31980 KB |
Output is correct |
13 |
Correct |
22 ms |
32128 KB |
Output is correct |
14 |
Correct |
22 ms |
31980 KB |
Output is correct |
15 |
Correct |
22 ms |
31980 KB |
Output is correct |
16 |
Correct |
23 ms |
31980 KB |
Output is correct |
17 |
Correct |
22 ms |
31980 KB |
Output is correct |
18 |
Correct |
22 ms |
31980 KB |
Output is correct |
19 |
Correct |
22 ms |
32128 KB |
Output is correct |
20 |
Correct |
22 ms |
31980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
31980 KB |
Output is correct |
2 |
Correct |
22 ms |
31980 KB |
Output is correct |
3 |
Correct |
22 ms |
31980 KB |
Output is correct |
4 |
Correct |
23 ms |
31980 KB |
Output is correct |
5 |
Correct |
22 ms |
31980 KB |
Output is correct |
6 |
Correct |
22 ms |
31980 KB |
Output is correct |
7 |
Correct |
22 ms |
31980 KB |
Output is correct |
8 |
Correct |
22 ms |
31980 KB |
Output is correct |
9 |
Correct |
22 ms |
31980 KB |
Output is correct |
10 |
Correct |
22 ms |
31980 KB |
Output is correct |
11 |
Correct |
24 ms |
31980 KB |
Output is correct |
12 |
Correct |
22 ms |
31980 KB |
Output is correct |
13 |
Correct |
22 ms |
32128 KB |
Output is correct |
14 |
Correct |
22 ms |
31980 KB |
Output is correct |
15 |
Correct |
22 ms |
31980 KB |
Output is correct |
16 |
Correct |
23 ms |
31980 KB |
Output is correct |
17 |
Correct |
22 ms |
31980 KB |
Output is correct |
18 |
Correct |
22 ms |
31980 KB |
Output is correct |
19 |
Correct |
22 ms |
32128 KB |
Output is correct |
20 |
Correct |
22 ms |
31980 KB |
Output is correct |
21 |
Runtime error |
64 ms |
64876 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
22 |
Halted |
0 ms |
0 KB |
- |