Two warehouses each keep a sorted (non-decreasing) log of shipment values: warehouse A has n values and warehouse B has m values. If the two logs were merged into one sorted list of n + m values, find the k-th smallest value in that merged list (1-indexed).
Line 1: three integers n, m, and k.
Line 2: n space-separated integers, sorted non-decreasing — warehouse A's log.
Line 3: m space-separated integers, sorted non-decreasing — warehouse B's log.
A single integer: the k-th smallest value among all n + m values combined.
Example 1
Input
3 3 4 1 3 5 2 4 6
Expected
4
Explanation
Merged in order: 1, 2, 3, 4, 5, 6. The 4th smallest value is 4.
Example 2
Input
2 1 1 10 20 5
Expected
5
Explanation
Merged in order: 5, 10, 20. The 1st smallest value is 5.
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 →