#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();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
3 ms |
348 KB |
Output is correct |
3 |
Correct |
3 ms |
344 KB |
Output is correct |
4 |
Correct |
3 ms |
348 KB |
Output is correct |
5 |
Correct |
2 ms |
348 KB |
Output is correct |
6 |
Correct |
2 ms |
348 KB |
Output is correct |
7 |
Correct |
3 ms |
348 KB |
Output is correct |
8 |
Correct |
3 ms |
348 KB |
Output is correct |
9 |
Correct |
3 ms |
348 KB |
Output is correct |
10 |
Correct |
3 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
3 ms |
348 KB |
Output is correct |
3 |
Correct |
3 ms |
344 KB |
Output is correct |
4 |
Correct |
3 ms |
348 KB |
Output is correct |
5 |
Correct |
2 ms |
348 KB |
Output is correct |
6 |
Correct |
2 ms |
348 KB |
Output is correct |
7 |
Correct |
3 ms |
348 KB |
Output is correct |
8 |
Correct |
3 ms |
348 KB |
Output is correct |
9 |
Correct |
3 ms |
348 KB |
Output is correct |
10 |
Correct |
3 ms |
344 KB |
Output is correct |
11 |
Execution timed out |
4019 ms |
856 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
4041 ms |
7708 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
3 ms |
348 KB |
Output is correct |
3 |
Correct |
3 ms |
344 KB |
Output is correct |
4 |
Correct |
3 ms |
348 KB |
Output is correct |
5 |
Correct |
2 ms |
348 KB |
Output is correct |
6 |
Correct |
2 ms |
348 KB |
Output is correct |
7 |
Correct |
3 ms |
348 KB |
Output is correct |
8 |
Correct |
3 ms |
348 KB |
Output is correct |
9 |
Correct |
3 ms |
348 KB |
Output is correct |
10 |
Correct |
3 ms |
344 KB |
Output is correct |
11 |
Execution timed out |
4019 ms |
856 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |