Simple solution in 2 lines


#1
sort(A.begin() , A.end()) ;

return A[0] + A[A.size() -1] ;