My Solution:
https://www.codechef.com/viewsolution/50418731

The problem is all about finding the number of inversions in an Array. Remember that the number of inversions for an Array of size N can be as large as \cfrac{N\times(N - 1)}{2} (for strictly decreasing sequence of integers).

Long story short, use long long int.

PS: You should think of a faster approach as your approach will TLE on N\ge10^5.

2 Likes

Thank you so much. It worked. I was almost having an existential crisis until you helped.

I just wanted to do it using binary search as everyone is using merge sort or upper bound methods in vector. Trying something different
Thank you again