The D. E. Shaw GroupOA #10
Minimum Operations to Make Array Equal
估计困难可在线判题
In each operation, choose any non-empty contiguous subarray of even length and apply +1, −1, +1, −1 to its elements in turn from left to right. The same range may be operated on repeatedly, and different ranges may also be chosen. Find the minimum number of operations to turn source into target; output −1 if it is impossible.
The standard input/output, the ranges added by this site, and the examples follow this problem's description.
输入格式
The first line contains n (original problem: 1≤n≤10^5); the next two lines contain the n source values and the n target values, respectively (original problem: −10^9≤element≤10^9).
输出格式
Output the minimum number of operations; output −1 if target is unreachable.
样例 1
输入:
2
0 0
1 -1
输出:
1
样例 2
输入:
2
0 0
-1 1
输出:
-1
样例 3
输入:
4
0 0 0 0
1 -1 1 -1
输出:
1