#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int maxn = 500100;
int N, A[maxn], Suf[maxn], Mx;
vector<int> pos;
int main() {
ios::sync_with_stdio(0); cin.tie(0);
cin >> N;
for (int i = 1; i <= N; ++i) {
cin >> A[i];
Mx = max(Mx, A[i]);
}
int q; cin >> q >> q >> q;
for (int i = N; i >= 1; --i) {
if (A[i] == Mx) pos.push_back(i);
Suf[i] = max(Suf[i + 1], A[i]);
}
reverse(pos.begin(), pos.end());
int l = 0, Ans = 0;
for (int i = 1; i <= N; ++i) {
while (l + 1 < (int)pos.size() && pos[l] <= i) ++l;
if (pos[l] <= i) break;
int len = pos[l] - i;
Ans = max(Ans, A[i] + Mx + Suf[pos[l] + len]);
}
l = 0;
for (int i = 1; i <= N; ++i) {
while (l + 1 < (int)pos.size() && pos[l + 1] < i) ++l;
if (pos[l] >= i) continue;
int len = i - pos[l];
Ans = max(Ans, Mx + A[i] + Suf[i + len]);
}
cout << Ans << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
3692 KB |
Output is correct |
2 |
Incorrect |
24 ms |
3692 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |