#include<bits/stdc++.h>
#define ll long long
#define ss second
#define ff first
using namespace std;
const int N = 222222;
int n, m;
ll a[N], b[N];
int main()
{
cin >> n;
for (int i=1; i<=n; i++) cin >> a[i], b[i] = a[i];
for (int i=2; i<=n; i++) b[i-1] = max(b[i], b[i-1]);
cin >> m;
int l, r, k;
ll ans = 0;
while (m--)
{
ans = 0;
cin >> l >> r;
k = (r - l + 2) / 3;
for (int i=1; i<=k; i++)
{
ans = max(ans, 1ll*(a[l] + a[l+i] + b[l+i+i]));
l++;
}
cout << ans << "\n";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
83 ms |
3400 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |