Help Needed in Solving KATARE CARPET

Problem Link:-

Can somebody tell the approach to this problem?

My guess is it’s a double binary search.
Sort the array.
Binary search the answer p from 0 to 10^18.
For each search, find the least element in the array that goes over p for each element and using that find the number of products with it that are less than p over all elements. If there are too few, increase p, else decrease p.