题目描述
求A[i] + B[j] == k 的 (i , j) 对
样例
算法1
(暴力枚举) $O(n^2)$
include[HTML_REMOVED]
using namespace std;
const int N = 100010;
int n, m, x;
int a[N];
int b[N];
int main(){
scanf(“%d%d%d”, &n, &m, &x);
for(int i = 0; i < n; i ) scanf(“%d”, &a[i]);
for(int i = 0; i < m; i ) scanf(“%d”, &b[i]);
int i = 0, j = m - 1;
while(i < n && j >= 0){
if(a[i] + b[j] > x) j –;
else if(a[i] + b [j] < x) i ++;
else
break;
}
cout << i << ‘ ‘ << j << endl;
return 0;
}
不写MarkDown?