이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |