This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define sz(v) int(v.size())
#define ar array
typedef long long ll;
const int N = 5e5+10, INF = 1e9+10;
int n, q, a[N];
void solve() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int q; cin >> q;
while (q--) {
int l, r; cin >> l >> r, --l, --r;
ll ans = 0;
for (int i = l; i <= r; i++) {
for (int j = i+1; j <= r; j++) {
for (int k = j+1; k <= r; k++) {
if (k - j >= j - i) {
ans = max(ans, (long long) a[i] + a[j] + a[k]);
}
}
}
}
cout << ans << '\n';
}
}
int main() {
ios::sync_with_stdio(false); cin.tie(0);
solve();
}
# | 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... |