A large automaker located in the Manaus Industrial Pole (PIM) manages a vast warehouse with $$$N$$$ different types of electronic components. The primary parts-picking system is efficient, with autonomous robots that fetch the needed components from the warehouse, based on optical sensors that identify the part type, and carry them to the main sorting conveyor, where they are sorted and sent to the assembly line.
Unfortunately, sensor failures can occur. In such situations, the factory relies on a contingency protocol: emergency robots remove components from the warehouse one at a time, but completely "blindly", without identifying which type of component they are picking up until it reaches the main sorting conveyor. As a result, in some situations, the robots may remove more units of certain components than necessary.
The factory has production targets that require $$$K_i$$$ units of component type $$$i$$$. Currently, the stock available in the warehouse has $$$C_i$$$ units of component $$$i$$$.
The logistics manager needs to know: in the worst possible scenario, what is the minimum number of components the robots must remove from the warehouse to guarantee that all the assembly line's requirements are fully met? If the stock is insufficient to guarantee that all targets can be met, the system must signal the impossibility of the operation by printing $$$-1$$$.
The first line contains an integer $$$N$$$ ($$$1 \leq N \leq 2 \times 10^{5}$$$), the number of component types.
The second line contains $$$N$$$ integers $$$C_1, C_2, \dots, C_N$$$ ($$$1 \leq C_i \leq 10^{4}$$$), representing the available stock quantity of each component.
The third line contains $$$N$$$ integers $$$K_1, K_2, \dots, K_N$$$ ($$$1 \leq K_i \leq 10^{4}$$$), representing the required target for each component.
Print a single line containing the minimum number of removals needed in the worst case to guarantee all targets, or $$$-1$$$ if it is impossible to guarantee that the targets can be met with the current stock.
310 20 302 5 10
52
25 51 10
-1
Explanation for example 1
Note that, acting blindly, the robots could remove all the components of types 2 and 3 before removing any unit of the first component. In this case, 52 components would be removed before the minimum required quantity of all of them is reached. Analyzing all the possibilities, it is possible to verify that this is the worst case.
| Название |
|---|


