제출 #1328388

#제출 시각아이디문제언어결과실행 시간메모리
1328388fv33단 점프 (JOI19_jumps)C++20
27 / 100
19 ms3540 KiB
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
constexpr ll inf = 3e18;

#define sz(x) (int)(x).size()
#define all(x) begin(x), end(x)

void solve() {
	int n;
	cin >> n;
	vector<ll> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	auto postmax = a;
	for (int i = n-2; i >= 0; i--) {
		postmax[i] = max(a[i], postmax[i+1]);
	}

	int q, l, r;
	cin >> q >> l >> r;
	assert(q == 1 && l == 1 && r == n);

	auto Get = [&](int i) { return i >= 0 && i < n ? a[i] : 0; };
	ll res = 0;
	for (int i = 0; i < n; i++) {
		ll mx = Get(i-1);
		for (int j = i + 1; j < n; j++) {
			res = max(res, a[i] + mx + postmax[j]);
			mx = max({mx, Get(2*i-j), (j+i)%2 ? 0 : Get((j+i)/2)});
			if (mx >= a[i]) break;
		}
	}
	cout << res << "\n";
}

signed main() {
	cin.tie(0)->sync_with_stdio(0);
	solve();
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...