#include <bits/stdc++.h>
using namespace std;
#define int long long
int32_t main(){
ios::sync_with_stdio(0);cin.tie(0);
int n;
cin >> n;
long long arr[n];
for(int i=0; i<n; i++) cin >> arr[i];
int q;
cin >> q;
for(int i=0; i<q; i++){
int l,r;
cin >> l >> r;
assert(l==1&&r==n);
}
long long suf[n];
suf[n-1]=arr[n-1];
for(int i=n-2; i>=0; i--) suf[i]=max(suf[i+1],arr[i]);
vector<pair<long long,int> > mono;
long long ans=0;
for(int i=0; i<n; i++){
while(!mono.empty()&&mono.back().second<arr[i]){
int a=mono.back().second;
if(i*2-a<n) ans=max(ans,arr[a]+arr[i]+suf[i*2-a]);
mono.pop_back();
}
if(!mono.empty()){
int a=mono.back().second;
if(i*2-a<n) ans=max(ans,arr[a]+arr[i]+suf[i*2-a]);
}
mono.push_back({arr[i],i});
}
cout << ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
18 ms |
3552 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |