[C++编程] 888. 公平的糖果交换

Alice and Bob have candy bars of different sizes: A[i] is the size of the i-th bar of candy that Alice has, and B[j] is the size of the j-th bar of candy that Bob has.
Since they are friends, they would like to exchange one candy bar each so that after the exchange, they both have the same total amount of candy. (The total amount of candy a person has is the sum of the sizes of candy bars they have.)
Return an integer array ans where ans[0] is the size of the candy bar that Alice must exchange, and ans[1] is the size of the candy bar that Bob must exchange.
If there are multiple answers, you may return any one of them. It is guaranteed an answer exists.

爱丽丝和鲍勃有不同大小的糖果棒:A[i] 是爱丽丝拥有的第 i 块糖的大小,B[j] 是鲍勃拥有的第 j 块糖的大小。
返回一个整数数组 ans,其中 ans[0] 是爱丽丝必须交换的糖果棒的大小,ans[1] 是 Bob 必须交换的糖果棒的大小。

示例 1:

输入:A = [1,1], B = [2,2]

示例 2:

输入:A = [1,2], B = [2,3]

示例 3:

输入:A = [2], B = [1,3]

示例 4:

输入:A = [1,2,5], B = [2,4]

解法一 带注释源代码 已通过官方测试

解法二 带注释源代码 已通过官方测试

解法三 带注释源代码 已通过官方测试

解法四 带注释源代码 已通过官方测试