数组大小才100,直接硬算,全部枚举
#include<stdio.h>
#include<stdlib.h>
int cmp3023(const void *i1, const void *i2)
{
return *(int *) i1 - *(int *) i2;
}
int main()
{
int n, m, i, j;
int a[100], b[100];
while (scanf("%d %d", &n, &m), n || m)
{
int sumt = 0, sumh = 0;
for (i = 0; i < n; i++)
{
scanf("%d", &a[i]);
sumt += a[i];
}
for (i = 0; i < m; i++)
{
scanf("%d", &b[i]);
sumh += b[i];
}
if ((sumt - sumh) % 2 != 0)
{
printf("-1\n");
continue;
}
qsort(a, n, sizeof(int), cmp3023);
qsort(b, m, sizeof(int), cmp3023);
int d = (sumt - sumh) / 2, found = 0;
for (i = 0; i < n && !found; i++)
for (j = 0; j < m; j++)
if (a[i] - b[j] == d)
{
printf("%d %d\n", a[i], b[j]);
found = 1;
break;
}
if (!found)
printf("-1\n");
}
return 0;
}