1. You are given two sorted arrays with N and M elements.
2. You are also given a number K.
3. You have to find K pairs with the smallest sums.
4. Note: A pair (u,v) consists of one element from the first array and one element from the second array.
5. display is a utility function, feel free to use it for debugging purposes.
6. main takes input from the users and creates the arrays.
7. This is a functional problem.
8. You have to complete the kSmallestPairs function. It takes as input both the arrays and K. It should return a List containing upto K lists of pairs with smallest sums.
9. Don't change the code of main and display.
Input Format
First line takes input N, the length of the first array. Second line takes input N space separated numbers representing the elements of first array. Third line takes input M, the length of the second array. Fourth line takes input M space separated numbers representing the elements of second. Fifth line takes input K. Input is handled for you.
Output Format
K pairs in ascending order with smallest sums in K lines. Output is handled for you.
Constraints
1 <= N, M <= 30000
Notice
Try First, Check Solution later
1. You should first read the question and watch the question video.2. Think of a solution approach, then try and submit the question on editor tab.3. We strongly advise you to watch the solution video for prescribed approach.Example
Input
3 1 1 2 3 1 2 3 2
Output
1 1 1 1