In the world of Amazon’s vast inventory management, you face a challenge of optimizing two inventories, inv1
and inv2
, each containing n
elements.
Your goal is to maximize the similarity between these inventories. The similarity is measured by the number of indices i
(0 ≤ i < n) where inv1[i]
equals inv2[i]
.
Amazon provides a unique tool, the “Inventory Optimizer”. This tool allows you to perform the following operation:
- Select two distinct indices
i
andj
(where 0 ≤ i, j < n and i ≠ j), provided that thej
th element ofinv1
is positive. - Apply the operation: add 1 to
inv1[i]
and subtract 1 frominv1[j]
.
Using the Inventory Optimizer, you can perform this operation any number of times (including zero) to maximize the similarity between inv1
and inv2
.
Constraints
1<=n<=1e5
1<=inv1[i],inv2[i]<=1e4