MAXFUN - Editorial

Since we need Ax<=Ay<=Az
firstly, I had sorted the array, and then,
I had taken Ax as a minimum element
Az as a maximum element
and Ay as the median of the array.

if(N is even) Ay = (A[(n-1)/2] + A[(n+1)/2])/2;
if(N is odd) Ay = (A[(n/2)]);

thus, ans = abs(Az - Ax) + abs(Ay - Ax) + abs(Az - Ay);

    sort(v.begin(),v.end());
    
    cout<<abs(v[n-1]-v[0]) + abs(v[n-1]-v[n-2]) + abs(v[n-2]-v[0]);