AcWing 800. 数组元素的目标和
原题链接
简单
作者:
跟着灿哥学切菜
,
2021-03-13 11:13:11
,
所有人可见
,
阅读 281
#include <iostream>
using namespace std;
const int N = 100010;
int a[N], b[N];
int n, m, x;
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];
for (int i = 0, j = m - 1; i < n; i ++) {
while (j >= 0 && a[i] + b[j] > x) j --;
if (a[i] + b[j] == x) cout << i << ' ' << j << endl;
}
return 0;
}
//此时是暴力写法,此时会超时。
/*#include <iostream>
using namespace std;
const int N = 100010;
int a[N], b[N];
int n, m, x;
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];
for (int i = 0; i < n; i ++) {
for (int j = 0; j < m; j ++) {
if (a[i] + b[j] == x) {
cout << i << ' ' << j << endl;
break;
}
}
}
return 0;
}*/