双指针
class Solution:
def purchasePlans(self, nums: List[int], target: int) -> int:
nums.sort()
n = len(nums)
j = n - 1
res = 0
for i in range(n):
while nums[i] + nums[j] > target and i < j:
j -= 1
if i < j:
res = (res + j - i) % int((1e9 + 7))
else:
break
return res