This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/*
author : abushbandit
contest : ---
*/
#include "bits/stdc++.h"
using namespace std;
#define all(x) x.begin(),x.end()
#define pb push_back
void solve() {
int n;
cin >> n;
int a[n];
for(int i = 0;i < n;i++){
cin >> a[i];
}
int mx[n][n] {};
for(int i = 0;i < n;i++){
mx[i][i] = a[i];
for(int j = i + 1;j < n;j++){
mx[i][j] = max(mx[i][j - 1],a[j]);
}
}
int q;
cin >> q;
for(int i = 0;i < q;i++){
int l,r;
cin >> l >> r;
l--;
r--;
int ans = 0;
for(int k = l;k <= r;k++){
for(int j = k + 1;j <= r;j++){
if(j + j - k > r) break;
int res = a[k] + a[j];
res += mx[j + (j - k)][r];
ans = max(ans,res);
}
}
cout << ans << "\n";
}
}
signed main() {
ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
int t = 1;
//~ cin >> t;
while(t--){
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... |