# Return indices in the two sum problem

Given an array unsorted P of integers and a number m. I am trying to write a code that returns indices i, and j to satisfy 8P[i] + 7P[j] = M with time O(n log n).

I iterated over P[0] to P[n-1] and searched for P[j] = (M - 8P[i])/7 using binary search. Here, I can get the values of P[i] and P[j], but the original index of j is changed while sorting before binary search. What could be the better way to get the index?

Create a $$2$$-d array $$D[n][2]$$, where $$D[i][0]$$ stores $$P[i]$$, and $$D[i][1]$$ stores the index $$i$$.