MergeSort

2.6

10 votes
Very-Easy
Problem

Given an array A on size N, you need to find the number of ordered pairs (i,j) such that i<j and A[i]>A[j].

Input:
First line contains one integer, N, size of array.
Second line contains N space separated integers denoting the elements of the array A.

Output:
Print the number of ordered pairs (i,j) such that i<j and A[i]>A[j].

Constraints:
1N106
1A[i]106

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

In the sample test case, the 3 ordered pairs will be (2,3), (2,4) and (3,4).
2<3 but A[2]>A[3]
2<4 but A[2]>A[4]
3<4 but A[3]>A[4]

Editor Image

?