Whats wrong in this solution? I am getting WA


#1

int Solution::solve(vector &arr)
{
int n=arr.size();
int ans=INT_MIN;
vectorright(n);
right[n-1]=arr[n-1];

for(int i=n-2;i>=0;i--)
    right[i]=max(right[i+1],arr[i]);

set<int>st;
st.insert(arr[0]);

for(int j=1;j<n-1;j++) 
{
            st.insert(arr[j]);
            auto itr = st.find(arr[j]);
            if(itr!=st.begin()) 
            {
                ans = max(ans,arr[j]+(*(--itr))+right[j+1]);
            }
}

    if(ans==INT_MIN)
        return 0;
    else
        return ans;

}