How to find maximum possible area between two pilars?

Given an array A of size N, A[i] represents the height of pillar at A[i]th x coordinate.
let A={3,8,5} then it means height of pillar at x=3 is 3 and x=8 is 8 and x=5 is 5 the what is the maximum area between any two pillar. In the above case the answer is maxArea=15 i.e. between 3 and 8. The area between two pillar at index i,j is defined as area=min(A[i],A[j])*(abs(A[]i-A[j])).

constraints

1<=n<=5*103

1<=A[i]<=109

NOTE:
Please do not propose the O(N2) solution.

Step 1:- Sort using Merge sort.
Step 2:- Store value of (max-A[i]) in another array B[]. //[A[i] in sorted order].
Step 3:- Now , calculate A[i]*B[i] & find largest element and store in AREA & print it .

Any problem , plz. comment again.