#K37607. Counting Suitable Knives
Counting Suitable Knives
Counting Suitable Knives
You are given a list of knives with their sharpness values and a list of required sharpness values for various ingredients. For each ingredient, determine how many knives are suitable. A knife is considered suitable if its sharpness value is greater than or equal to the ingredient's required sharpness.
Formal Description:
For an ingredient with required sharpness \( r \), its corresponding answer is the count of all knives such that \( knife \ge r \). Mathematically, if the knives' sharpness values are represented by the array \( K \), then the answer for each \( r_i \) in the required list is:
\[ count_i = \#\{ k \in K\;:\; k \geq r_i \} \]The input size can be large, so an efficient algorithm (like sorting combined with binary search) should be used.
inputFormat
The first line of input contains two integers \( n \) and \( m \) (1 \(\leq n, m \leq 10^5\)) representing the number of knives and the number of ingredients, respectively.
The second line contains \( n \) space-separated integers representing the sharpness values of the knives.
The third line contains \( m \) space-separated integers representing the required sharpness values for each ingredient.
outputFormat
Output a single line with \( m \) space-separated integers. The \( i \)-th integer should be the number of knives that have a sharpness value greater than or equal to the \( i \)-th required sharpness value.
## sample3 2
10 15 20
12 17
2 1
</p>