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 i64 long long
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
void Solve(void) {
int N; cin >> N;
vector<int> a(N + 1);
for (int i = 1; i <= N; i ++) cin >> a[i];
int Q; cin >> Q; while (Q --) {
int L, R; cin >> L >> R;
int gap = (R - L + 1);
i64 ans = 0;
for (int mask = 0; mask < (1 << gap); mask ++) {
i64 cur = 0;
int d = -1, prev = -1, cnt = 0;
bool works = true;
for (int b = 0; b < gap; b ++) {
if (mask >> b & 1) {
cnt ++;
cur = cur + a[b + L];
if (prev == -1) prev = b;
else if (d == -1) {
d = b - prev;
prev = b;
} else if (d > b - prev) {
works = false; break;
}
}
}
if (cnt == 3 && works) {
ans = max(ans, cur);
}
}
cout << ans << "\n";
}
}
signed main() {
ios_base::sync_with_stdio(false); cin.tie(0);
cout << fixed << setprecision(10);
int Tests = 1; // cin >> Tests;
while (Tests --) {
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... |