数组元素的目标和

发布于 22 天前  1 次阅读


数组元素的目标和

#include <bits/stdc++.h>

using namespace std;
const int N = 1e5 + 10, INF = 0x3f3f3f3f, MOD = 998244353;
int n, m, x, a[N], b[N];

int main() {
    scanf("%d%d%d", &n, &m, &x);
    for (int i = 1; i <= n; ++i) scanf("%d", a + i);
    for (int i = 1; i <= m; ++i) scanf("%d", b + i);
    for (int i = 1, j = m; i <= n; ++i) {
        while (j >= 1 && a[i] + b[j] > x) j--;
        if (a[i] + b[j] == x) {
            printf("%d %d", i - 1, j - 1);
            return 0;
        }
    }
    return 0;
}