C++ 代码
//对每一个r,都存在l恰好使和小于等于x,随着r增大,l减小。所以递增r时,只需递减l即可,无需回退
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int a[N], b[N];
int main()
{
int n, m, x;
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 l = n - 1, r = 0;
for (; r < m; r++)
{
while (a[l] + b[r] > x) l--;
if (a[l] + b[r] == x) break;
}
cout << l << ' ' << r;
return 0;
}