Hongjun's matrix
Time limit2sMemory limit512 MB
Given sequences A and B of length N, find the K-th smallest value among all N^2 products A_i * B_j.
- Level
Medium7 of 10
- Topics
- Binary search, Sorting, Math, Two pointers
- Solved
- No attempts yet
Problem
Hongjun has two sequences and , each of length . He builds an matrix whose entry in row and column is .
Hongjun sorts all entries in non-decreasing order and wants to know the value that lands in position . Positions are counted from 1, and a value that appears several times is counted once for each entry that produces it. Write the program that finds the -th value for him, since sorting is slow for Hongjun.
Input
The first line contains and , separated by a space. (, )
The second line contains the elements of the sequence , separated by spaces.
The third line contains the elements of the sequence , separated by spaces.
Every element of both sequences is an integer between and .
Output
Print the -th smallest entry of the matrix.