// Muallif: Azimjon Mehmonali o'g'li
#include <bits/stdc++.h>
using namespace std;
#define int long long
const long double PI = 3.1415926535897;
const int mod = 1000000007LL;
const int INF = 1e18;
const int N = 500500;
int a[N], t[4 * N];
// void build(1)
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
// build();
int q;
cin >> q;
while (q--) {
int l, r;
cin >> l >> r;
vector<pair<int, int>> v;
for (int i = l; i <= r; i++) {
v.emplace_back(a[i], i);
}
sort(v.rbegin(), v.rend());
int tl = v[0].second, tr = v[1].second;
if (tl > tr) {
swap(tl, tr);
}
int re = 0;
for (int i = 1; i <= n; i++) {
vector<int> d{tl, tr, i};
sort(d.begin(), d.end());
if (i == tl || i == tr || l > i || i > r
|| d[2] - d[1] < d[1] - d[0])
continue;
re = max(re, a[i]);
}
cout << v[0].first + v[1].first + re << endl;
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
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 |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
52 ms |
7852 KB |
Output is correct |
2 |
Correct |
38 ms |
7860 KB |
Output is correct |
3 |
Correct |
38 ms |
7796 KB |
Output is correct |
4 |
Incorrect |
56 ms |
7876 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
- |