# Same as the editorial solution, yet TLE . PLS TELL ME WHERE AM I WRONG?

#1

int getLower(set s,int val){
// is valu se chota num jo maximum bhi ho sabhi chote nums mein se.
auto it=lower_bound(s.begin(),s.end(),val);
if(it!=s.begin()){
it–;
return(*it);
}
return -1;
}
int Solution::solve(vector &A) {
int n=A.size();
int max_sum=0;
set s;
s.insert(A[0]);
int suffix[n];
suffix[n-1]=-1;
// vector<int prefix(n,-1);
for(int i=n-2;i>=0;i–){
// cout<<i<<" ";
int temp=max(suffix[i+1],A[i+1]);

``````    if(temp>A[i])
{
suffix[i]=temp;
}
else{
suffix[i]=-1;
}
}
for(int i=1;i<n-1;i++){
// int max_left=-1;
int max_right=suffix[i];
if(max_right==-1){
continue;
}
int left_max=getLower(s,A[i]);
s.insert(A[i]);
if(left_max==-1){
continue;
}
max_sum=max(max_sum,left_max+max_right+A[i]);
}
return max_sum;
``````

}

#2

Nakal ke liye bhi akal chahiye hoti hai. LMAO. And btw way if it’s editorial solution, editorial is wrong. You are wrong at copying only. LOL

#3

https://codeforces.com/blog/entry/17347