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 endl '\n'
#define pb push_back
#define ll long long
#define int long long
const long long inf=1e18+1;
const int MOD=1e9+7;
const int N=5e5+1;
signed main()
{
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int n; cin>>n;
int a[n];
for(int i=0;i<n;i++)cin>>a[i];
int q; cin>>q;
while(q--){
int l,r,ans=0; cin>>l>>r; l--; r--;
for(int i=r;i>=l;i--){
for(int j=i-1;j>=l;j--){
for(int k=j-1;k>=j-(i-j) && k>=l;k--){
ans=max(ans,a[i]+a[j]+a[k]);
}
}
}
cout<<ans<<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... |