CitadelOA #14
Math with Lego Blocks
估计中等可在线判题
考点(AI 标注)贪心调度
Replace every 0 in the two arrays with an arbitrary positive integer, keeping the other values unchanged, so that the two totals are equal and as small as possible; output −1 if there is no solution. The filled values are not limited by the original arrays' upper bound of 10000.
输入格式
The first line contains n m, the second line contains rowA, and the third line contains rowB; 1≤n,m≤100000, original elements 0..10000.
输出格式
Output a single integer, the answer.
样例 1
输入:
2 1
0 2
3
输出:
3
样例 2
输入:
1 2
1
0 0
输出:
-1
样例 3
输入:
2 1
0 0
0
输出:
2
样例说明
The outputs of the three public examples are, in order: 3; -1; 2. These answers were verified by independent enumeration or direct simulation.