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;
long long c,d,x,y,z,n,q,l,r,kq;
int i,j,k;
long long st[2000005],a[1000001];
void buildtree(int id,int l,int r)
{
if (l==r)
{
st[id]=a[l]; return;
}
int mid=(l+r)/2;
buildtree(id*2,l,mid);
buildtree(id*2+1,mid+1,r);
st[id]=max(st[id*2],st[id*2+1]);
}
long long get(int id,int l,int r,int u,int v)
{
if (v<l || r<u) return 0;
if (u<=l && r<=v) return st[id];
int mid=(l+r)/2;
return max(get(id*2,l,mid,u,v),get(id*2+1,mid+1,r,u,v));
}
void sub1()
{
buildtree(1,1,n);
for (int i=1;i<=q;i++)
{
cin>>l>>r; kq=0;
for (int j=l+1;j<r;j++)
{
for (int k=l;k<j;k++)
{
z=j-k+j;
if (z<=r)
{
c=a[k]+a[j]+get(1,1,n,z,r);
kq=max(kq,c);
}
}
}
cout<<kq<<"\n";
}
}
int main()
{
//freopen("chonqua.inp", "r" ,stdin);
//freopen("chonqua.out", "w" ,stdout);
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin>>n;
for (int i=1;i<=n;i++)
{
cin>>a[i];
}
cin>>q;
sub1();
}
# | 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... |