I just wanted to bring it under notice that there are weak test cases in this problem.
Proof:
My solution.
My solution runs in O(N ^ 2), but the constraints allow at most O(N log N).
I should have got 50 points, but got 100. Please look into this matter.