intbin_search(int b[], int left, int right, int target){ int i = left, j = right, mid; while (i < j) { mid = (i + j) >> 1; if (b[mid] > target) j = mid; elseif (b[mid] < target) i = mid + 1; elsereturn mid; } return-1; }
voidmatrix_search(int a[], int b[], int target){ int i = 0, j = m-1; while (m >= 0 && i < n) { if (a[i] + b[j] > target) j--; elseif (a[i] + b[j] < target) i++; else { printf("%d %d\n", i, j); return; } } printf("-1 -1\n"); }
intmain(){ scanf("%d %d %d", &n, &m, &x); int a[n], b[m]; for (int i = 0; i < n; ++i) scanf("%d", &a[i]); for (int i = 0; i < m; ++i) scanf("%d", &b[i]); // 二分 // for (int i = 0; i < n; ++i) { // int j = bin_search(b, 0, m, x - a[i]); // if (j != -1) { // printf("%d %d", i, j); // break; // } // } matrix_search(a, b, x); return0; }