The logic is pretty simple.
Construct two arrays of pair of integers, L and R.
In the first position of each element l of L we put in the value l we receive and in the second position, we put in the index. Create a similar array for R.
Now sort the array L in decreasing order, and R in increasing order.
The score of the i-th person would be the sum of the positions of its corresponding l in L and its corresponding r in R.
For example, if n = 3, and the l and r values are
The L and R would be, after sorting,
Now, \text{score}[0] = 2 + 2 = 4, \text{score}[1] = 0 + 1, \text{score}[2] = 1 + 0.
Though sadly I was getting WA in the test itself, I have no idea why. My logic is sound.
So, I just wrote a quick brute-force solution and got 15.