Count queries below sum limit
Your task
Given a list of integers, a batch of queries, and an integer limit, count how many queries select a range whose sum is strictly below the limit. Each query is a pair [l, r] with 0 <= l <= r < n, selecting elements l through r inclusive. Return the number of qualifying queries. Values may be negative. Example: values = [8, 2, 5, 1], queries = [[0, 1], [1, 3], [2, 3]], limit = 9 gives 2, the range sums are 10, 8, and 6.
Examples
count_below_limit(values: list[int], queries: list[list[int]], limit: int) -> intExample 1
Input
count_below_limit([8, 2, 5, 1], [[0, 1], [1, 3], [2, 3]], 9)Output
2