Problem Statement
You are given an integer n
followed by n
pairs of integers. Additionally, two integers left
and right
are provided, representing an inclusive range [left, right]
. The task is to print all pairs where both the sum and the product of the integers in each pair fall within the given range [left, right]
.
Approach
To solve this problem, we first need to read and store the n
pairs of integers. Then, for each pair, we calculate the sum and the product of the two integers. We check if both the sum and the product fall within the inclusive range [left, right]
. If they do, we print the pair.
Complexity Analysis
-
Time Complexity: The time complexity is O(n), where
n
is the number of pairs. This is because we iterate through the list of pairs once, performing constant-time operations (addition, multiplication, and comparisons) for each pair. -
Space Complexity: The space complexity is O(n) due to the storage of the pairs in a vector. The additional space used by the program for storing variables is negligible (O(1)).