이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
string to_string(string s) { return s; }
template <typename T> string to_string(T v) {
	bool first = true;
	string res = "[";
	for (const auto &x : v) {
		if (!first)
			res += ", ";
		first = false;
		res += to_string(x);
	}
	res += "]";
	return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
void dbg_out() { cout << endl; }
template <typename Head, typename... Tail> void dbg_out(Head H, Tail... T) {
	cout << ' ' << to_string(H);
	dbg_out(T...);
}
#ifdef DEBUG
#define dbg(...) cout << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif
int N, Q;
vector<int> A;
int main() {
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cin >> N;
	A.resize(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	vector<vector<int>> bestmid(N, vector<int>(N, -1));
	vector<vector<int>> dp(N, vector<int>(N, -1));
	for (int l = 0; l < N; l++) {
		pair<int,int> maxi(-1e9, -1e9);
		for (int r = l+1; r < N; r++) {
			if (!((l-r)&1)) {
				maxi = max(maxi, make_pair(A[(l+r)>>1], (l+r)>>1));
			}
			if (l+2 <= r) {
				bestmid[l][r] = maxi.second;
				dp[l][r] = max(dp[l][r], A[l]+A[r]+maxi.first);
				dbg(l, r, dp[l][r]);
			}
		}
	}
	for (int l = N-1; l >= 0; l--) {
		for (int r = l+2; r < N; r++) {
			dp[l][r] = max(dp[l][r], max(dp[l][r-1], dp[l+1][r]));
		}
	}
	cin >> Q;
	int l, r;
	for (int i = 0; i < Q; i++) {
		cin >> l >> r, l--, r--;
		cout << dp[l][r] << '\n';
	}
}
| # | 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... |