You are given a 2D integer array pairs, where pairs[i] = [a_i, b_i] holds a pair of numbers, and an integer array queries. For each queries[j], count how many pairs have a sum strictly greater than queries[j].
More formally, for each query queries[j], find the number of indices i such that pairs[i][0] + pairs[i][1] > queries[j].
Return an array answer where answer[j] is the answer to the j-th query.
Function Signature
def count_pairs(pairs: list[list[int]], queries: list[int]) -> list[int]:
Rules
-
answer[j]
belongs to
queries[j]
, so the output has the same length as
queries
and keeps its order.
-
Pairs are counted by index. Two pairs with the same values both count.
-
A pair whose sum equals the query does not count.
Constraints
-
1 <= len(pairs) <= 10^5
-
-10^9 <= pairs[i][0], pairs[i][1] <= 10^9
-
1 <= len(queries) <= 10^5
-
-10^9 <= queries[j] <= 10^9
Examples
Input: pairs = [[1,2],[3,4],[5,6]], queries = [5,7,10]
Output: [2,1,1]
The pair sums are 3, 7 and 11. Two of them exceed 5, and only 11 exceeds 7 or 10. The sum 7 does not count for the query 7 because the comparison is strict.
Input: pairs = [[1,1],[2,2],[3,3]], queries = [1,3,6]
Output: [3,2,0]
The pair sums are 2, 4 and 6. All three exceed 1, two exceed 3, and none exceeds 6.
Input: pairs = [[-5,2],[0,0],[4,-4],[10,-1]], queries = [0,-3,-4,9]
Output: [1,3,4,0]
The pair sums are -3, 0, 0 and 9. Only 9 exceeds 0, the two zeros and 9 exceed -3, all four exceed -4, and nothing exceeds 9. The two zero sums come from different pairs, so both count.