Pairs On Line -Geometric Algorithm

getting tle in two cases
ide: https://ide.codingblocks.com/s/217174

@Vishal123 your algorithm is O(n ^2), you need to use O(nlogn) algorithm to solve this, please use binary search or maps to solve this question.

how to do it by using map

hey can tell you the pairs which form the ans fom this input
5 1 1
1 2 3 4 2

(1,2), (1,5), (2,3), (3,4), (5,3).

but 5 is not in the input array then how it can form the pair

these are indices of the elements in the array not the actual elements.