题目描述
模板题:双指针
C++代码
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n, m, x;
int a[N], b[N];
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(i < n && j >= 0){
if(a[i] + b[j] == x){
cout << i << " " << j << endl;
break;
}
else if(a[i] + b[j] > x)
j--;
else
i++;
}
*/
int j = m - 1;
for(int i = 0; i < n; i++){
while(j >= 0 && a[i] + b[j] > x)
j--;
if(j >= 0 && a[i] + b[j] == x){
cout << i << " " << j << endl;
break;
}
}
}