nums in non-decreasing order.left = 0 and right = nums[n - 1] - nums[0].left < right, perform the following steps:
a. Calculate the middle point mid = left + (right - left) // 2.
b. Use a greedy approach to count the number of valid pairs with a difference less than or equal to mid.
c. If the count is at least p, update right = mid.
d. Otherwise, update left = mid + 1.left as the minimum maximum difference after the binary search completes.