//
// Created by adavy on 5/28/2025.
//
//
// Created by adavy on 5/28/2025.
//
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int ssz = 524288;
ll INF = 1e18;
int n;
vector<ll> nums;
signed main(){
    cin >> n;
    nums.resize(n);
    for(int i=0;i<n;++i){
        cin >> nums[i];
    }
    int q;
    cin >> q;
    for(int qq=0;qq<q;++qq){
        ll mxans = -INF;
        int l, r; cin >> l >> r; l--; r--;
        for(int a=l;a<=r;++a){
            for (int b = a+1;b<=r;++b){
                for(int c = b+1; c <= r; ++ c){
                    if (c-b >= b-a) mxans = max(mxans, nums[a] + nums[b] + nums[c]);
                }
            }
        }
        cout << mxans << endl;
    }
}
| # | 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... |