利用了两个数组都是从小到大排序的,然后双指针的方法就会很简单了
#include <iostream>
using namespace std;
const int N = 100010;
int a[N], b[N];
int m, n, x;
int main()
{
cin >> n >> m >> x;
for(int i = 0; i < n; i ++ ) cin >> a[i];
for(int i = 0; i < m; i ++ ) cin >> b[i];
int i = 0, j = m - 1;
while(a[i] + b[j] != x)
{
while(a[i] + b[j] > x) j --;
while(a[i] + b[j] < x) i ++;
}
cout << i << " " << j <<endl;
}