Two price lists are given: list A with p values and list B with q values. Consider every possible pair sum a_i + b_j (there are p * q of them, counting repeated values as separate pairs). Report the k-th smallest of these sums, where the smallest sum is the 1st.
Line 1: three integers p, q, and k.
Line 2: p space-separated integers, list A.
Line 3: q space-separated integers, list B.
A single integer: the k-th smallest pair sum.
Example 1
Input
2 2 3 1 7 2 3
Expected
9
Explanation
The four sums are 3, 4, 9, 10. Sorted, the 3rd smallest is 9.
Example 2
Input
3 1 2 1 2 3 5
Expected
7
Explanation
The sums are 6, 7, 8. The 2nd smallest is 7.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →