| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1293429 | ducdev | Candies (JOI18_candies) | C++17 | 131 ms | 32956 KiB |
// Author: 4uckd3v - Nguyen Cao Duc
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX_N = 2e5;
const int MOD = 1e9 + 7;
const ll INF = 1e18;
int n;
int a[MAX_N + 5];
namespace SUBTASK_1 {
const int N = 2000;
ll dp[N + 5][N + 5];
void Solve() {
for (int i = 0; i <= n; i++)
for (int j = 0; j <= n; j++) dp[i][j] = -INF;
for (int i = 0; i <= n; i++) dp[0][i] = 0;
for (int i = 1; i <= (n + 1) >> 1; i++) {
for (int j = i; j <= n; j++) {
dp[i][j] = dp[i][j - 1];
if (j == 1) dp[i][j] = a[1];
if (j >= 2) dp[i][j] = max(dp[i][j], dp[i - 1][j - 2] + a[j]);
};
cout << dp[i][n] << '\n';
};
};
}; // namespace SUBTASK_1
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
if (fopen("MAIN.INP", "r")) {
freopen("MAIN.INP", "r", stdin);
freopen("MAIN.OUT", "w", stdout);
};
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
};
SUBTASK_1::Solve();
};
Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
