数组元素的目标和

链接 : https://www.acwing.com/problem/content/802/

#include <bits/stdc++.h>
using namespace std;
#define IO ios::sync_with_stdio(false);cin.tie(0); cout.tie(0)
inline int lowbit(int x) { return x & (-x); }
#define ll long long
#define pb push_back
#define PII pair<int, int>
#define fi first
#define se second
#define inf 0x3f3f3f3f
const int N = 1e5 + 7;
int a[N], b[N];
    
int main() {
    IO;
    int n, m, x;
    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 = n - 1, j = 0; i >= 0 ; --i) {
        while (j < m && a[i] + b[j] < x) ++j;
        if (a[i] + b[j] == x) cout << i << " " << j << '\n';
    }
    return 0;
}

posted @ 2021-01-27 20:49  phr2000  阅读(74)  评论(0编辑  收藏  举报