atcoder#ABC254H. [ABC254Ex] Multiply or Divide by 2
[ABC254Ex] Multiply or Divide by 2
Score : points
Problem Statement
You are given multisets with non-negative integers each: and . You can perform the operations below any number of times in any order.
- Choose a non-negative integer in . Delete one instance of from and add one instance of instead.
- Choose a non-negative integer in . Delete one instance of from and add one instance of instead. ( is the greatest integer not exceeding .)
Your objective is to make and equal (as multisets). Determine whether it is achievable, and find the minimum number of operations needed to achieve it if it is achievable.
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
If the objective is achievable, print the minimum number of operations needed to achieve it; otherwise, print -1
.
3
3 4 5
2 4 6
2
You can achieve the objective in two operations as follows.
- Choose to delete one instance of from and add one instance of instead. Now we have .
- Choose to delete one instance of from and add one instance of instead. Now we have .
1
0
1
-1
You cannot turn into .