#include<bits/stdc++.h>
using namespace std;
#define thanchu() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define read(n,a) for (int i=1; i<=n; i++) cin>>a[i];
#define readln(n,a,pp) for (int i=1; i<=n; i++) {cin>>a[i]; pp[a[i]]++;}
#define ull unsigned long long int
#define task "TEXT"
const long long maxn=1e6+4;
long long n,m,a[maxn+1],d=0,s[maxn+1];
void doc()
{
#ifndef ONLINE_JUDGE
// freopen(task".INP", "r", stdin);
//freopen(task".OUT", "w", stdout);
#endif
cin>>n;
read(n,a);
cin>>m;
}
void trau()
{
while (m--)
{
int l, r;
cin>> l >>r;
long long ma=LLONG_MIN;
for (int x=l; x<=r-2; ++x)
{
for (int y=x+1; y<=(r+x)/2; ++y)
{
for (int z=2*y-x; z<=r; ++z)
{
ma=max(ma, a[x]+a[y]+a[z]);
}
}
}
cout<<ma<<endl;
}
}
void xuly()
{
while (m--)
{
int l,r;
cin>>l>>r;
long long x=l,m_ai=a[l],ma=LLONG_MIN;
for (int y=x+1; y<=(r+x)/2; ++y)
{
for (int z=2*y-x; z<=r; ++z)
{
ma=max(ma, m_ai+a[y]+a[z]);
}
if (a[y]>=m_ai)
{
m_ai=a[y];
x=y;
}
}
cout<<ma<<endl;
}
}
signed main()
{
thanchu();
doc();
trau();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
2 ms |
444 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
2 ms |
600 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
2 ms |
444 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
2 ms |
600 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Execution timed out |
4058 ms |
604 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4050 ms |
2908 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
2 ms |
444 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
2 ms |
600 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Execution timed out |
4058 ms |
604 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |