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>
#define int long long
using namespace std;
int N,Q,A[500000],L,R,C[500000];
vector<array<int,3>>PA;
int CALC(){
stack<pair<int,int>>F;
for(int i = 0; i < N; i += 1){
while(F.size()){
pair<int,int>TOP = F.top();
PA.push_back({TOP.second, i, i * 2 - TOP.second});
if(TOP.first > A[i])break;
F.pop();
}
F.push({A[i],i});
}
int MX = 0;
for(int i = 0; i < PA.size();i += 1){
MX = max(MX,C[PA[i][2]] + A[PA[i][0]] + A[PA[i][1]]);
}
return MX;
}
void CALC2(){
for(int i = 0; i < 500000; i += 1)C[i] = (int)-3e8;
for(int i = N - 1; i >= 0; i -= 1){
C[i] = max(C[i + 1], A[i]);
}
}
int32_t main()
{
cin.tie(0),iostream::sync_with_stdio(0);
cin>>N;
for(int i = 0; i < N; i += 1){
cin>>A[i];
}
CALC2();
cout<<CALC();
cin>>Q;
vector<array<int,3>>STO;
for(int i = 0; i < Q; i += 1){
cin>>L>>R;
STO.push_back({L,R,i});
}
sort(STO.rbegin(),STO.rend());
}
Compilation message (stderr)
jumps.cpp: In function 'long long int CALC()':
jumps.cpp:18:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::array<long long int, 3> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
18 | for(int i = 0; i < PA.size();i += 1){
| ~~^~~~~~~~~~~
# | 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... |