Acwing 800. 数组元素的目标和
- 题目描述
- 代码展示
题目描述
代码展示
#include<iostream>
using namespace std;
const int N = 1e5 + 10;
int a[N], b[N];
int main()
{
int n , m , x, i = 0, j = m - 1;
cin >> n >> m >> x;
for (int i = 0; i < n; i ++ ) scanf("%d", &a[i]);
for (int j = 0; j < m; j ++ ) scanf("%d", &b[j]);
for( i = 0, j = m - 1; i < n; i++){
while(j >= 0 && a[i] + b[j] > x) j --;
if(j >= 0 && a[i] + b[j] == x) printf("%d %d\n", i, j);
}
return 0;
}