Resource Allocation Across Two Storage Rows

Company: BlackRock

Difficulty: easy

Problem Statement

Resource Allocation Across Two Storage Rows Problem Description A warehouse keeps its stock in **two rows of storage units**. The first row has `n` units and the second row has `m` units. Each unit holds a certain amount of a resource, and a unit that currently holds nothing is recorded as `0`. New resources are about to be delivered. Every **empty** unit - and only an empty unit - must be filled with a **strictly positive** amount, that is, an integer greater than `0`. Units that already hold something are never changed. The delivery is considered balanced when, after all empty units have been filled, the total amount of resources in the first row equals the total amount in the second row. Report the **smallest** total that each row can be made to hold, or `-1` if no filling of the empty units can make the two row totals equal. Input Format The first line contains an integer `n`, the length of the first row. Each of the next `n` lines contains one integer: an amount held by a unit of