#P10417. K-th Smallest Sum Pair
K-th Smallest Sum Pair
K-th Smallest Sum Pair
You are given two sequences \(A\) and \(B\), of lengths \(n\) and \(m\) respectively. Define a sequence \(C\) that contains the sum of every pair of elements taken from \(A\) and \(B\); formally, \(C = \{A_i + B_j \mid 1 \le i \le n, \, 1 \le j \le m\}\). Note that if there are duplicate sums, each occurrence is counted separately. For example, in the multiset \(\{1, 1, 2, 3\}\), both the smallest and the second smallest elements are \(1\), and \(3\) is the fourth smallest element.
Your task is to determine the \(K\)-th smallest number in the sequence \(C\).
Note: The sequences \(A\) and \(B\) are not necessarily sorted.
inputFormat
The first line contains three integers \(n\), \(m\), and \(K\) where:
- \(n\) is the length of sequence \(A\).
- \(m\) is the length of sequence \(B\).
- \(K\) is the position of the smallest sum to find.
The second line contains \(n\) integers representing the elements of sequence \(A\).
The third line contains \(m\) integers representing the elements of sequence \(B\).
outputFormat
Output a single integer which is the \(K\)-th smallest sum in the sequence \(C\).
sample
2 2 3
1 2
3 4
5