| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1295673 | thaibeo123 | Triple Jump (JOI19_jumps) | C++20 | 267 ms | 239364 KiB |
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define NAME "CONCERT"
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define MASK(x) (1ll << (x))
#define BIT(x, i) (((x) >> (i)) & 1)
const int N = 5005;
int n, q;
int a[N], mx[N][N], dp[N][N];
void input() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
}
void solve() {
for (int i = 1; i <= n; i++) {
for (int j = i; j <= n; j++) {
mx[i][j] = max(mx[i][j - 1], a[j]);
}
}
for (int i = 1; i <= n - 2; i++) {
dp[i][i + 2] = a[i] + a[i + 1] + a[i + 2];
}
for (int i = n; i >= 1; i--) {
for (int j = i + 3; j <= n; j++) {
int len = j - i + 1;
dp[i][j] = max(dp[i][j - 1], dp[i + 1][j]);
int cur = a[i] + a[j] + mx[i + 1][i + (len - 1) / 2];
dp[i][j] = max(dp[i][j], cur);
}
}
cin >> q;
while (q--) {
int l, r;
cin >> l >> r;
cout << dp[l][r] << "\n";
}
}
signed main() {
if (fopen(NAME".INP", "r")) {
freopen(NAME".INP", "r", stdin);
freopen(NAME".OUT", "w", stdout);
}
cin.tie(0)->sync_with_stdio(0);
input();
solve();
return 0;
}
Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
