#P8837. Maximum Buyers Problem
Maximum Buyers Problem
Maximum Buyers Problem
There are \(n\) students and \(m\) items in a store. The \(i\)-th student has \(w_i\) money and the \(j\)-th item costs \(c_j\) money. Each student can buy at most one item and each item can be bought at most once. Determine the maximum number of students who can purchase an item.
Constraints:
- \(1 \leq n, m \leq 10^5\)
- \(1 \leq w_i, c_j \leq 10^9\)
Hint: A greedy strategy works by sorting both the students' amounts and the item prices.
inputFormat
The input consists of three lines:
- The first line contains two integers \(n\) and \(m\).
- The second line contains \(n\) integers, where the \(i\)-th integer is \(w_i\) — the amount of money the \(i\)-th student has.
- The third line contains \(m\) integers, where the \(j\)-th integer is \(c_j\) — the cost of the \(j\)-th item.
outputFormat
Output a single integer: the maximum number of students who can purchase an item.
sample
3 3
3 1 2
2 1 4
2