#P12342. Minimum Operations for Positive Differences
Minimum Operations for Positive Differences
Minimum Operations for Positive Differences
Given two arrays A and B each of length \(n\) where \(A = \{a_1,a_2,\cdots,a_n\}\) and \(B = \{b_1,b_2,\cdots,b_n\}\), define a new array \(C = A - B\) such that \(c_i = a_i - b_i\). You are allowed to perform the following operation any number of times on array \(B\): change any one element of \(B\) to any integer. After performing all operations, you are allowed to reorder array \(B\) arbitrarily. Then, the array \(C\) is recalculated as \(c_i = a_i - b_{\pi(i)}\) for some permutation \(\pi\) of \(\{1, 2, \ldots, n\}\).
The goal is to ensure that every element of \(C\) is a positive integer, i.e. \(c_i > 0\) for all \(i\). Determine the minimum number of operations needed on \(B\) to achieve this.
Hint: Since you can reorder \(B\) after modifications, you may greedily match the smallest available elements from \(B\) with the smallest elements in \(A\) such that \(b < a\). The answer is \(n - (\text{maximum matching count})\). For each unmatched pairing, an operation is needed to adjust \(B\).
inputFormat
The input consists of three lines:
- The first line contains a single integer \(n\) (\(1 \leq n \leq 10^5\)).
- The second line contains \(n\) space-separated integers representing the array \(A\).
- The third line contains \(n\) space-separated integers representing the array \(B\).
outputFormat
Output a single integer — the minimum number of operations required so that after your operations and an optimal reordering of \(B\), every \(c_i = a_i - b_i\) is greater than 0.
sample
3
2 3 4
1 2 3
0