This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int nx=5e5+5;
ll n, a[nx], mx[nx], res, q, l, r;
stack<ll> s;
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>n;
for (int i=1; i<=n; i++) cin>>a[i];
mx[n+1]=-2e9;
for (int i=n; i>=1; i--) mx[i]=max(mx[i+1], a[i]);
cin>>q>>l>>r;
for (int i=1; i<=n; i++)
{
while (!s.empty()&&s.top()<=a[i]) res=max(res, a[s.top()]+a[i]+mx[min(n+1, (ll)(2*i-s.top()))]), s.pop();
if (!s.empty()) res=max(res, a[s.top()]+a[i]+mx[min(n+1, (ll)(2*i-s.top()))]);
s.push(i);
//cout<<i<<' '<<res<<'\n';
}
cout<<res;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |