题目
参考
import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int L1 = scanner.nextInt();
int L2 = scanner.nextInt();
int[] A = new int[L1];
int[] B = new int[L2];
for (int i = 0; i < L1; i++) {
A[i] = scanner.nextInt();
}
for (int i = 0; i < L2; i++) {
B[i] = scanner.nextInt();
}
int suma = Arrays.stream(A).sum();
int sumb = Arrays.stream(B).sum();
int ava = (suma + sumb) / 2;
int value = Math.abs(ava - Arrays.stream(A).sum());
Arrays.sort(A);
Arrays.sort(B);
if (suma > sumb) {
for (int item : A) {
if (Arrays.binarySearch(B, item - value) >= 0) {
System.out.println(item + " " + (item - value));
break;
}
}
} else {
for (int item : A) {
if (Arrays.binarySearch(B, item + value) >= 0) {
System.out.println(item + " " + (item + value));
break;
}
}
}
}
}
https://blog.csdn.net/weixin_52908342/article/details/135128253