算法1
O(n)
Java 代码
import java.util.*;
import java.io.*;
public class Main {
final static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
final static BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));
public static void main(String[] args) throws IOException{
String[] str = reader.readLine().split("\\s+");
int n = Integer.parseInt(str[0]);
int m = Integer.parseInt(str[1]);
int x = Integer.parseInt(str[2]);
int[] a = new int[n];
int[] b = new int[m];
str = reader.readLine().split("\\s+");
for(int i = 0; i < n; i++){
a[i] = Integer.parseInt(str[i]);
}
str = reader.readLine().split("\\s+");
for(int i = 0; i < m; i++){
b[i] = Integer.parseInt(str[i]);
}
int j = m-1;
for(int i = 0; i < n; i++){
while(j >= 0 && a[i] + b[j] > x){
j--;
}
if(a[i] + b[j] == x){
System.out.println(i+" "+j);
return;
}
}
}
}