#include<bits/stdc++.h>
using namespace std;
typedef long long ll; typedef pair<int, int> pii;
#define ff first
#define ss second
#define pb emplace_back
#define AI(x) begin(x),end(x)
template<class I> bool chmin(I&a, I b){ return a > b ? (a=b, true) : false; }
template<class I> bool chmax(I&a, I b){ return a < b ? (a=b, true) : false; }
#ifdef OWO
#define debug(args...) LKJ("\033[1;32m[ " + string(#args) + " ]\033[0m", args)
template<class I> void LKJ(I&&x){ cerr << x << endl; }
template<class I, class...T> void LKJ(I&&x, T&&...t){ cerr << x << ", "; LKJ(t...); }
template<class I> void OI(I a, I b){ while(a < b) cerr << *a << " \n"[next(a) == b], ++a; }
#else
#define debug(...) 0
#define OI(...) 0
#endif
const int kN = 500005;
int N, Q, A[kN];
int L[kN], R[kN];
void input(){
cin >> N;
for(int i = 1; i <= N; ++i)
cin >> A[i];
cin >> Q;
for(int i = 0; i < Q; ++i)
cin >> L[i] >> R[i];
}
int suf[kN];
int f(int a, int b){
return A[a] + A[b] + suf[ b + (b-a) ];
}
void solve(){
suf[N] = A[N];
for(int i = N-1; i >= 1; --i)
suf[i] = max(A[i], suf[i+1]);
int ans = 0;
deque<int> dq;
for(int i = 2; i < N; ++i){
while(!dq.empty() and f(dq.back(), i) <= f(i-1, i))
dq.pop_back();
dq.pb(i-1);
while(dq.size() > 1 and f(dq[0], i) <= f(dq[1], i))
dq.pop_front();
chmax(ans, f(dq[0], i));
}
cout << ans << '\n';
}
signed main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
input();
solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Incorrect |
0 ms |
332 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Incorrect |
0 ms |
332 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
1864 KB |
Output is correct |
2 |
Correct |
20 ms |
1900 KB |
Output is correct |
3 |
Correct |
24 ms |
1820 KB |
Output is correct |
4 |
Correct |
30 ms |
1812 KB |
Output is correct |
5 |
Correct |
21 ms |
1884 KB |
Output is correct |
6 |
Correct |
27 ms |
1944 KB |
Output is correct |
7 |
Incorrect |
17 ms |
1868 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Incorrect |
0 ms |
332 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |