atcoder#ARC120C. [ARC120C] Swaps 2
[ARC120C] Swaps 2
Score : points
Problem Statement
Given are two sequences of length each: and . Determine whether it is possible to make equal by repeatedly doing the operation below (possibly zero times). If it is possible, find the minimum number of operations required to do so.
- Choose an integer such that , and do the following in order:- swap and ;
- add to ;
- subtract from .
- swap and ;
- add to ;
- subtract from .
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
If it is impossible to make equal , print -1
.
Otherwise, print the minimum number of operations required to do so.
3
3 1 4
6 2 0
2
We can match with in two operations, as follows:
- First, do the operation with , making .
- Next, do the operation with , making .
We cannot meet our objective in one or fewer operations.
3
1 1 1
1 1 2
-1
In this case, it is impossible to match with .
5
5 4 1 3 2
5 4 1 3 2
0
may equal before doing any operation.
6
8 5 4 7 4 5
10 5 6 7 4 1
7