#abc254h. Ex - Multiply or Divide by 2
Ex - Multiply or Divide by 2
Score : points
问题陈述
给定两个包含 个非负整数的多重集: 和 。
您可以按照任意顺序执行以下操作任意次数:
- 从 中选择一个非负整数 。从 中删除一个 的实例,并添加一个 的实例。
- 从 中选择一个非负整数 。从 中删除一个 的实例,并添加一个 的实例。( 表示不超过 的最大整数。)
您的目标是使 和 相等(作为多重集)。
确定这一目标是否可以实现,并在可实现的情况下找到实现所需的最小操作次数。
以上为通义千问 qwen-max 翻译,仅供参考。
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
.
Sample Input 1
3
3 4 5
2 4 6
Sample Output 1
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 .
Sample Input 2
1
0
1
Sample Output 2
-1
You cannot turn into .
update @ 2024/3/10 10:50:50