Untitled

mail@pastecode.io avatar
unknown
c_cpp
a month ago
555 B
2
Indexable
Never
#include <bits/stdc++.h>
using namespace std;


int main() {
    int k, n;
    cin >> k >> n;
    int a[n], b[n];
    
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for(int i = 0; i < n; i++) {
        cin >> b[i];
    }
    
    sort(a, a + n);
    sort(b, b + n);
    long long res = 0;
    for(int i = 0; i < n; i++) {
        if(a[i] >= k) {
            res += n;
        }
        else {
            int idx = lower_bound(b, b + n, k - a[i]) - b;
            res += n - idx;
        }
    }
    cout << res << endl;
    return 0;
}
Leave a Comment