You are given two sorted arrays A and B of sizes N and M respectively. C is the following:
Example
A = {1,2,3}, B = {1,3,6} then C = {2,3,4,4,5,6,7,8,9}
2 is first largest
3 is second largest
4 is third largest
4 is fifth largest
5 is sixth largest
Task
You are given two integers X and Y. Determine all the possible pairs of i,j such that A[i]+B[j] is:
This means that you have to determine all possible i and j such that Xth greatest<A[i]+B[j]< Yth greatest
Input format
Output format
Print the output in two lines as follows:
Constraints
For given arrays A and B, all possible combinations of A*B in sorted order (sorted by sum value)
(Sum, A's index, B's index) ->
(3,1,1) (4,1,2) (6,1,3) (6,2,1) (7,2,2) (8,1,4) (9,2,3) (11,2,4)
Solution for given X and Y will be ->
3 (Number of Pairs)
(1,3) (2,1) (2,2) (All pairs in form (A's index, B's index))
Output
3
(1,3) (2,1) (2,2)