# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
233086 | triple_fault | Triple Jump (JOI19_jumps) | C++14 | 4066 ms | 3704 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/* fucking change this 2020 */
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <set>
#include <map>
#include <random>
#define ll long long
using namespace std;
//rng
/*
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll rand(ll L, ll R) {
return uniform_int_distribution<ll>(L, R)(rng);
}*/
void foo() {
ll n; scanf("%lld", &n);
ll vals[n];
for (ll i = 0; i < n; ++i) scanf("%lld", &vals[i]);
ll q; scanf("%lld", &q);
while (q --) {
ll a, b; scanf("%lld %lld", &a, &b);
--a; --b;
ll mxv = -1, idx = -1;
for (ll i = a; i <= b; ++i)
if (vals[i] > mxv) {
mxv = vals[i];
idx = i;
}
ll ans = 0;
for (ll i = a; i < idx; ++i) {
ll dif = idx - i;
for (ll j = idx + dif; j <= b; ++j)
ans = max(ans, vals[i] + vals[j]);
}
for (ll i = a; i < idx; ++i) {
ll dif = idx - i;
for (ll j = max(i - dif, a); j < i; ++j) ans = max(ans, vals[i] + vals[j]);
}
for (ll i = idx + 1; i <= b; ++i) {
ll dif = i - idx;
for (ll j = i + dif; j <= b; ++j) ans = max(ans, vals[i] + vals[j]);
}
printf("%lld\n", ans + vals[idx]);
}
}
int main(void) {
ll t = 1;
while (t --) foo();
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... |