AcWing 800. 数组元素的目标和
原题链接
简单
作者:
szywdwd
,
2021-05-05 22:26:29
,
所有人可见
,
阅读 140
#include <iostream>
#include <vector>
using namespace std;
int main()
{
int n, m, x;
cin >> n >> m >> x;
vector<int> A, B;
for(int i = 0; i < n; ++i) {
int tmp;
cin >> tmp;
A.push_back(tmp);
}
for(int i = 0; i < m; ++i) {
int tmp;
cin >> tmp;
B.push_back(tmp);
}
int i = 0, j = m - 1;
for(i = 0, j = m - 1; i < n; ++i) {
while(j > -1 && A[i] + B[j] > x) --j;
if(A[i] + B[j] == x) {
cout << i << ' ' << j;
return 0;
}
}
return 0;
}