#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <bitset>
#include <iomanip>
#include <memory>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <climits>
#include <cassert>
using namespace std;
#define mp make_pair
#define add push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define mem(a,b) memset(a, b, sizeof(a))
#pragma GCC optimize("unroll-loops")
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
typedef pair <int, int> pii;
typedef vector <int> lnum;
const int N = (int)1e6 + 100;
const int maxn = (int)1e3 + 100;
const int base = (int)1e9;
const int mod = (int)1e9 + 7;
const int inf = INT_MAX;
const long long ll_inf = LLONG_MAX;
const long double PI = acos((long double)-1.0);
const long double eps = 1e-8;
long long dp[2003][2003], A[2003];
void solve() {
int n; cin >> n;
for (int i = 1; i <= n; ++i) cin >> A[i];
int to = (n + 1) / 2;
for (int i = 0; i <= n; ++i) {
for (int j = 0; j <= n; ++j) {
dp[i][j] = -ll_inf;
}
}
dp[0][0] = dp[0][1] = 0;
dp[1][1] = A[1];
for (int j = 2; j <= n; ++j) {
for (int i = 0; i <= j; ++i) {
dp[i][j] = dp[i][j - 1];
if (i) dp[i][j] = max(dp[i][j], dp[i - 1][j - 2] + A[j]);
}
}
for (int i = 1; i <= to; ++i) cout << dp[i][n] << '\n';
}
int main() {
//ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
//#define Freopen
#ifdef Freopen
#ifndef _MSC_VER
#define TASK ""
freopen(TASK".in", "r", stdin);
freopen(TASK".out", "w", stdout);
#endif
#endif
int T = 1;
//scanf("%d", &T);
for (; T; --T) solve();
#ifdef DEBUG
cerr << double(1.0 * clock() / CLOCKS_PER_SEC) << '\n';
#endif
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
65 ms |
31736 KB |
Output is correct |
2 |
Correct |
60 ms |
31756 KB |
Output is correct |
3 |
Correct |
59 ms |
31956 KB |
Output is correct |
4 |
Correct |
58 ms |
31956 KB |
Output is correct |
5 |
Correct |
57 ms |
31960 KB |
Output is correct |
6 |
Correct |
59 ms |
32156 KB |
Output is correct |
7 |
Correct |
56 ms |
32156 KB |
Output is correct |
8 |
Correct |
58 ms |
32232 KB |
Output is correct |
9 |
Correct |
58 ms |
32232 KB |
Output is correct |
10 |
Correct |
58 ms |
32232 KB |
Output is correct |
11 |
Correct |
60 ms |
32240 KB |
Output is correct |
12 |
Correct |
58 ms |
32240 KB |
Output is correct |
13 |
Correct |
61 ms |
32252 KB |
Output is correct |
14 |
Correct |
60 ms |
32272 KB |
Output is correct |
15 |
Correct |
60 ms |
32424 KB |
Output is correct |
16 |
Correct |
59 ms |
32424 KB |
Output is correct |
17 |
Correct |
58 ms |
32460 KB |
Output is correct |
18 |
Correct |
57 ms |
32460 KB |
Output is correct |
19 |
Correct |
61 ms |
32460 KB |
Output is correct |
20 |
Correct |
59 ms |
32460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
65 ms |
31736 KB |
Output is correct |
2 |
Correct |
60 ms |
31756 KB |
Output is correct |
3 |
Correct |
59 ms |
31956 KB |
Output is correct |
4 |
Correct |
58 ms |
31956 KB |
Output is correct |
5 |
Correct |
57 ms |
31960 KB |
Output is correct |
6 |
Correct |
59 ms |
32156 KB |
Output is correct |
7 |
Correct |
56 ms |
32156 KB |
Output is correct |
8 |
Correct |
58 ms |
32232 KB |
Output is correct |
9 |
Correct |
58 ms |
32232 KB |
Output is correct |
10 |
Correct |
58 ms |
32232 KB |
Output is correct |
11 |
Correct |
60 ms |
32240 KB |
Output is correct |
12 |
Correct |
58 ms |
32240 KB |
Output is correct |
13 |
Correct |
61 ms |
32252 KB |
Output is correct |
14 |
Correct |
60 ms |
32272 KB |
Output is correct |
15 |
Correct |
60 ms |
32424 KB |
Output is correct |
16 |
Correct |
59 ms |
32424 KB |
Output is correct |
17 |
Correct |
58 ms |
32460 KB |
Output is correct |
18 |
Correct |
57 ms |
32460 KB |
Output is correct |
19 |
Correct |
61 ms |
32460 KB |
Output is correct |
20 |
Correct |
59 ms |
32460 KB |
Output is correct |
21 |
Runtime error |
376 ms |
66080 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
22 |
Halted |
0 ms |
0 KB |
- |