Can anyone suggest a way to descrease the time complexity - getting TLE


#1

int Solution::solve(vector &A) {
int n = A.size();
int msum=0;
int ri=n-1;
int mi=n-2;
int li=0;
while(mi>0)
{
if(A[ri]<A[mi])
{
ri=mi;
mi–;
continue;
}
for(int i=0;i<mi;i++)
{
if(A[i]<A[mi])
{
int tsum=A[ri]+A[i]+A[mi];
if(tsum>msum)
msum=tsum;
}
}
mi–;
}
return msum;
}