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 <iostream>
#include <map>
#include <vector>
#include <climits>
#include <stack>
#include <string>
#include <queue>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <cctype>
#include <bitset>
#include <iomanip>
#include <cstring>
#include <numeric>
using namespace std;
#define int long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define fi first
#define se second
int32_t main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, q, a, b;
cin>>n;
vector<int> vect(n+1);
for (int i=1; i<=n; ++i)cin>>vect[i];
cin>>q;
while (q--){
cin>>a>>b;
int res=0;
for (int i=b; i>=a; --i)for (int j=b, p=b, mx=0; j>=i+1; --j){
while (p>=2*j-i)mx=max(mx, vect[p]), --p;
res=max(res, vect[i]+vect[j]+mx);
}
cout<<res<<"\n";
}
}
# | 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... |