二分查找
C++ 代码
#include<bits/stdc++.h>
#define rep(i,j,k) for(int i=j;i<=k;i++)
#define per(i,j,k) for(int i=j;i>=k;i--)
#define PII pair<int,int>
#define x first
#define y second
#define mset(i,j) memset(i,j,sizeof(i))
#define ll long long
#define INF 0x3f3f3f3f
#define IO std::ios::sync_with_stdio(false); cin.tie(0)
const int N=100010;
int a[N],b[N];
int n,m,x;
int method(int x,int l,int r){
while(l<=r){
int mid=l+r>>1;
if(b[mid]==x) return mid;
else if(b[mid]>x) r=mid-1;
else l=mid+1;
}
return -1;
}
using namespace std;
int main(){
IO;
int i,j;
cin>>n>>m>>x;
rep(i,0,n-1)cin>>a[i];
rep(i,0,m-1)cin>>b[i];
for(i=0;i<n;i++){
if(x<=a[i]) continue;
int left = x-a[i];
int j=method(left,0,m-1);
if(j!=-1){
cout<<i<<' '<<j;
break;
}
}
return 0;
}